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);
}
}