14
我正在尝试排除Web应用程序的注销功能。当您登录时,该应用程序为其域设置了多个Cookie。下面是目前注销程序:PHP - 为什么我不能摆脱这个会话ID cookie?
- 你点击一个链接,就会进入退出页面
- 登出页面运行调用
session_destroy()
并遍历所有cookie域,并将其设置为一个功能过期(见下面的代码) - 注销页面然后重定向到一个登录页面,这是直线HTML。
在这个过程结束时,所有其他的饼干都没有设置,但PHPSESSID
的cookie仍然存在,具有相同的价值,并且仍然被设置在会议结束时到期。
我在这里错过了什么?
这里的注销功能我上面提到的:
function log_out_current_user() {
// Destroy the session
if (isset($_SESSION)) {
session_destroy();
}
// Expire all of the user's cookies for this domain:
// give them a blank value and set them to expire
// in the past
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000);
setcookie($name, '', time()-1000, '/');
}
// Explicitly unset this cookie - shouldn't be redundant,
// but it doesn't hurt to try
setcookie('PHPSESSID', '', time()-1000);
}
}