【发布时间】:2011-04-28 17:01:18
【问题描述】:
我正在尝试对 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);
}
}
【问题讨论】:
标签: php session cookies session-cookies