我正在为登录注销系统创建会话。但我的session_destroy无效。一旦我点击退出,会话变量仍然存在。
以下是我创建会话的方式。
session_start();
$username = $_GET['username'];
$_SESSION["username"] = $username;
header('Location: employeepage.php');
然后我就会收到它。
session_destroy();
header('Location: login.php');
当我使用jquery单击logout时。我重定向到应该销毁会话的页面。
$('#logoutbtn').live("click",function(){
window.location.replace("logout.php");
});
这就是我如何摧毁它。
session_destroy();
header('Location: login.php');
有什么想法吗?
答案 0 :(得分:1)
您还需要在使用session_start()
之前致电session_destroy
。
来自manual:
session_start();
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finally, destroy the session.
session_destroy();