Trouble reading cookies

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Trouble reading cookies

Post by mzfp2 »

This a baffling problem for me, I have a script which creates a cookie to store someone's username, should they wish to the site to remember their username for next time they visit.

I can create the cookies, and they seem to be set correctly, I have checked Cookies directory for IE, and the cookie is there, in FireFox, I view the list of cookies, and again, the cookie is there.

The trouble seems to be accessing the cookie values. I have tried using $HTTP_COOKIE_VARS, and also $_COOKIE but not succeding, below is the code which attempts to read and display the cookie value :

Code: Select all

global $HTTP_COOKIE_VARS;

$username = $HTTP_COOKIE_VARS['username'];
print $username;
I can't see what im doing wrong here, the code below is used to set the cookie :

Code: Select all

setcookie('username', $username, time()+99999);

$username is not empty, I have checked foor this, and the correct values are being written to the cookie, but I just cannot access them!

i hope someone can help with this

Musaffar
Post Reply