Page 1 of 1
IIS & Cookies
Posted: Tue Mar 04, 2003 12:04 pm
by nefus
Hi guys, I seem to be able to set cookies with IIS, but not read them. I've been trying if (!$cookiename). Am I doing something wrong. Is there a way to pull the fields out of the cookie? Honestly, I am a rank beginner and would appreciate some pointers.
Posted: Tue Mar 04, 2003 2:28 pm
by twigletmac
Have a read of this:
viewtopic.php?t=511
You probably need to be using:
Code: Select all
if (!isset($_COOKIE['cookiename'])) {
Mac
Posted: Thu Mar 06, 2003 12:14 pm
by nefus
I use
setcookie("cookiename",$user,time()+(90*90*12),'sitename');
then to read it I have
if (!isset($_COOKIE["cookiename"]))
{ go to unauthorized page;
} else { do these things }
I have verified the cookie is being written. But I cannot get the second part of the code to work.
FYI - Unsure if this in related but I also cannot get session variables to be read either. I have checked and session.save_path is fine.
update: echo $_COOKIE['cookiename'] doesn't work. I get an error that says Undefined index: dmvalid in C:\Inetpub\clients\dm\htdocs\rulespost.php on line 1.
Posted: Fri Mar 07, 2003 1:50 am
by twigletmac
There's a bunch of things you need to be aware of when setting cookies - have you read this in the
manual:
PHP manual wrote:Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);.
Mac
Posted: Fri Mar 07, 2003 10:46 am
by nefus
That command gives me a response. The others still do not work.
print_r($_COOKIE);
echo $_COOKIE['cookiename'];
will result in
Array ( [PHPSESSID] => c19b0e31595b2447f531da9af32889ac )
Notice: Undefined index: cookiename in C:\Inetpub\clients\dm\htdocs\rulespost.php on line 1
Posted: Mon Mar 10, 2003 3:26 am
by twigletmac
Are you testing for the cookie on the same page on which you are setting it? That's the main reason I posted the quote from the manual above.
Mac
Posted: Mon Mar 10, 2003 8:45 am
by nefus
No, I'm checking for the cookie on another page.

Posted: Mon Mar 10, 2003 8:55 am
by twigletmac
Which browser are you using?
Mac
Posted: Mon Mar 10, 2003 9:20 am
by nefus
IE6, IE5 and Mozilla 1.21. All 3 have been tested. This is very depressing. :-/.