【问题标题】:destrying session not working破坏会话不起作用
【发布时间】:2012-08-10 03:11:12
【问题描述】:

我正在为登录注销系统创建会话。但是我的 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');

有什么想法吗?

【问题讨论】:

    标签: php jquery session


    【解决方案1】:

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

    来自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();
    

    【讨论】:

    • 哇。那成功了!谢谢!将在 8 分钟内接受游览答复。
    猜你喜欢
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 2013-11-10
    • 2012-07-19
    • 1970-01-01
    • 2010-11-07
    • 2015-06-09
    相关资源
    最近更新 更多