简体   繁体   English

PHP Cookies不会删除!

[英]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: 选中该选项后,我将cookie设置为一个月,如下所示:

$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. 然后,我有一个注销脚本来杀死cookie,将值设置为null并将过期日期设置为过去一小时。

$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: 当我运行注销脚本时,Firebug这样说:

Set-Cookie userID=deleted; Set-Cookie userID =已删除; expires=Tue, 02-Feb-2010 16:43:15 GMT u=deleted; expires = Tue,02-Feb-2010 16:43:15 GMT u =已删除; expires=Tue, 02-Feb-2010 16:43:15 GMT 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? 设置Cookie的唯一时间是运行登录脚本时,为什么它们不会消失? 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. 我正在设置路径Cookie,并且注销脚本与登录脚本位于不同的目录中。 I've set them to domain cookies and they're working now. 我已经将它们设置为域Cookie,并且它们现在正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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