Reputation: 500
I have a site with an option to "stay logged in." When the option is checked, I set cookies for one month like so:
$expire = time()+60*60*24*30;
setcookie("user_ID", $userid, $expire);
setcookie("u", $username, $expire);
etc.
Then I have a logout script to kill the cookies, setting the value to null and the expire date one hour in the past.
$expire2 = time()-60*60;
foreach ($_COOKIE as $c_id => $c_value)
{
setcookie($c_id, NULL, $expire2);
}
When I run the logout script, Firebug says this:
Set-Cookie userID=deleted; expires=Tue, 02-Feb-2010 16:43:15 GMT u=deleted; expires=Tue, 02-Feb-2010 16:43:15 GMT
But when I go back to the main or any other page, I'm still logged in! The only time I set the cookie is when I run the login script, so why won't they die? Could it have anything to do with local time being behind GMT?
Upvotes: 0
Views: 1202
Reputation: 500
Never mind. As with most mistakes I make, this one was pretty stupid. I was setting path cookies, and my logout script was in a different directory than the login script. I've set them to domain cookies and they're working now.
Upvotes: 3