我正在尝试对Web应用程序的注销功能进行故障排除。登录后,该应用程序为其域设置了多个cookie。以下是当前注销过程:
-
您单击一个链接,该链接会将您发送到注销页面
-
注销页运行一个调用
session_destroy()
并循环访问域的所有cookie,并将其设置为在过去过期(请参见下面的代码)
-
然后,注销页面重定向到一个登录页面,该页面是直接的HTML。
在此过程结束时,所有其他cookie均未设置,但
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);
}
}