Ok, im having trouble retrieving info from a cookie...
here is how the cookie was set:
setcookie("loggedin['username']", "$username", time()+36000);
and after its set, i tried to do:
echo "welcome <b>".$loggedin['username']."</b><br />";
and it returns "welcome "
I also tried:
echo "welcome <b>".$HTTP_COOKIE_VARS['loggedin']['username']."</b><br />";
same problem...(i can't use $_COOKIE, my host hasn't upgraded)
what am i doing wrong?
cookie problems
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
maybe include a $ sign $loggedin['username']setcookie("loggedin['username']", "$username", time()+36000);
and try without any "
setcookie($loggedin['username'],$username,time()+36000);
I don't use quotes and it works okay, I also name my cookies something like 'user'
setcookie('user',$username,time()+36000);
Then I check for
if ($user){
}
else{
}
I am struggling to see how $loggedin['username'] is going to work. lets say I log in and it creates a cookie called Mike, so when you do your check for a cookie it would need to check for $Mike, but how does your code know that for me it has to find a variable called $Mike, and don't say "because there is a cookie" because the servers doesn't know there is a cookie unless it knows what it is called and it doesn't know what it is called until it finds a cookie aaarrrgggh Catch 22.
Just call your cookie something like 'user' and check for the existence of that variable because it is the value associated with $user that is important.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact: