View Full Version : Dissappearing Cookie

05-20-2004, 11:37 PM
Hi there, I am having trouble accessing a cookie on different pages of my site. I have print_r($_COOKIE); at the top of two different pages, one returns the cookie contents, the other returns Array ( ).

I set the cookie is set at:
http://www.domain.com/login/index.php and print_r($_COOKIE); returns the cookie value once the user is logged in and the cookie is set.

On the page:
http://www.domain.com/activities/activity1.php the print_r($_COOKIE); request returns an empty array: Array ( ).

Note, I can surf the site and then go back to http://www.domain.com/login/ and it will still show the cookie contents, it only seems to "disappear" when I am on certain pages.

Are there any obvious causes for this?


05-21-2004, 12:35 AM
Quite simple in end.

The problem was that the cookie was registered from a sub-directory on the site but I had left the directory attribute of setcookie() as empty, there for it was only available to files within that directory (and it's sub-directories).

Correct code was to set the cookie with: setcookie('cookiename', $login_value, 0, '/');