Page 1 of 1

Help with weird setcookie() behavior

Posted: Sun Aug 24, 2008 9:42 pm
by jchonphoenix
Hello guys, I'm trying to set a user authentication cookie and im getting some odd errors.

basically this is my command for setting the cookies: setcookie("auth", "1", 0, "/", "domain.com", 0);

and when i store that in a variable it returns true. Hoewver, in $_COOKIE['auth'] the cookie is never set. and when i go to view cookies in my browser it doesn't show up. Help?

Re: Help with weird setcookie() behavior

Posted: Mon Aug 25, 2008 1:28 am
by Ziq
It's very strange.

Try this code:

Code: Select all

<?php
setcookie("auth", "1");
print_r($_COOKIE);
?>
Necessarily reload page in browser.

Re: Help with weird setcookie() behavior

Posted: Mon Aug 25, 2008 8:17 pm
by jchonphoenix
setcookie("auth", "1");
worked. Thanks. However, Can anyone give an explanation for why this is? thanks

Re: Help with weird setcookie() behavior

Posted: Tue Aug 26, 2008 4:03 am
by Ziq
jchonphoenix wrote:setcookie("auth", "1");
worked. Thanks. However, Can anyone give an explanation for why this is? thanks
Read set_cookie()

I think you not correct use parameters path and domain.