0
不知道爲什麼這樣做。但我的logout.php代碼工作正常,重定向到主頁,會話被破壞。當我回到某個頁面時,它會引起一箇舊會話,我不明白它。頁面session_destroy後帶回舊會話
我的繼承人login文件
$_SESSION['id'] = $row['user_id'];
$_SESSION['username'] = $row['username'];
setcookie('id', $row['user_id'], time() + (60 * 60 * 24 * 2));
setcookie('username', $row['username'], time() +(60 * 60 * 24 * 2));
這裏是我的註銷文件
// if the user is logged in, delete the cookie to log them out
session_start();
if (isset($_SESSION['id'])) {
$_SESSION = array();
// delete the user id and the username cookie by setting their expirations to an hour ago (3600)
if (isset($_COOKIE[session_name()])) {
setcookie('session_name()', '', time() - 3600);
}
//destroy the session
session_unset();
session_destroy();
}
//delete the user id and username cookies
setcookie('id', '', time() - 3600);
setcookie('username', '', time() - 3600);
unset($_COOKIE['id']);
unset($_COOKIE['username']);
unset($_SESSION['id']);
unset($_SESSION['username']);
// redirect to the home page
$home_url = 'http://page.com/';
header('Location: ' . $home_url);
exit();
這裏是我有我的網頁上的代碼:
在session_start();
// If the session vars aren't set, try to set them with a cookie
if (!isset($_SESSION['id'])) {
if (isset($_COOKIE['id']) && isset($_COOKIE['username'])) {
$_SESSION['id'] = $_COOKIE['id'];
$_SESSION['username'] = $_COOKIE['username'];
}
}
此代碼在主頁上工作正常,但是當我進入子目錄時,它會引發一個隨機的舊會話。
我想我想出了我的問題。我有一個單獨的登錄從一個子目錄,所以當我從我的主目錄登出,顯然這是單獨的。我將不得不從一個子目錄的loggin中找出一些東西 – mxcoop98 2013-03-21 03:06:11