1

我正在为登录注销系统创建一个会话。但是我的 session_destroy 不起作用。单击注销后,会话变量仍然存在。

这是我创建会话的方式。

session_start();
$username = $_GET['username'];
$_SESSION["username"] = $username;
header('Location: employeepage.php');

那么这就是我收到它的方式。

session_destroy();
header('Location: login.php');

当我使用 jquery 单击注销时。我重定向到应该销毁会话的页面。

$('#logoutbtn').live("click",function(){
    window.location.replace("logout.php");
});

这就是我如何摧毁它。

session_destroy();
header('Location: login.php');

有任何想法吗?

4

1 回答 1

1

session_start()您还需要在使用前致电session_destroy

手册

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();
于 2012-08-10T03:13:58.233 回答