简体   繁体   中英

PHP Cookies Won't Delete!

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM