【发布时间】:2015-05-26 08:39:45
【问题描述】:
我不知道为什么我不能删除 cookie 或它的价值:
我有简单的登录脚本,当用户输入正确的登录详细信息时,这是
setcookie('logged', $admin['username'], time()+60*60*24*365);
此外,session_start() 出现在所有页面上。
当我想注销用户时,会发生以下情况:
if($page=='logoff') {
setcookie('logged', "", time() - 3600);
unset($_COOKIE['logged']); // tried also this
session_destroy();
$_SESSION=null;
header("Location: index.php"); // if this is removed, the code below acts like there's no $_COOKIE['logged'] or it's empty (until refresh)
}
一旦它被重定向到 index.php,$_COOKIE['logged'] 就会返回旧值,就像某些东西会再次设置它一样(没有什么是肯定的,我什至删除了唯一的登录 cookie 设置行)
我找不到类似问题的解决方案。在 chrome 和 IE 中测试。
【问题讨论】:
-
设置cookie的时候把时间设为0怎么样?
-
检查您的浏览器时间设置与服务器时间,或将其设置为
-100000而不是-3600,以确保服务器时间也已过去。 -
我找不到关于这些类似主题的答案,我已经尝试了他们的建议。