Page 1 of 1

cookie problems

Posted: Thu Jun 13, 2002 4:33 pm
by hob_goblin
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?

Posted: Thu Jun 13, 2002 5:21 pm
by mikeq
setcookie("loggedin['username']", "$username", time()+36000);
maybe include a $ sign $loggedin['username']

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.

Posted: Thu Jun 13, 2002 5:26 pm
by hob_goblin
well i had loggedin['username'] and loggedin['password'],
well I'm going to go try out some of the things you said and see if they work