4

每当我尝试使用其他用户登录时,我看到用户名没有改变,这意味着 $_SESSION['username'] 也没有改变,那么我的 logout.php 脚本有什么问题?

<?php 
session_start();
$_SESSION = array(); 
session_unset();
session_destroy();
ob_start();
ob_end_flush();

header("location:index.php");
?>
4

3 回答 3

0

您还需要从参考中删除会话 cookie,就像这样。

<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
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();
?>

另一个很好的参考,George Brighton 在评论中提到的PHP Session Introduction 。

于 2013-09-11T16:14:01.110 回答
0

在 session_destroy() 之前尝试 unset:

未设置($_SESSION);session_destroy();

第一个销毁会话中保存的数据。最后一次销毁 COOKIE 会话 ID。

于 2013-09-11T21:49:52.687 回答
0

会话是一个数组......我认为你在做什么没有任何意义。

正确的不会是这样吧?..

session_start();
$_SESSION['anything'] = array();

现在

session_destroy();

或者

unset($_SESSION['anything']);
于 2013-09-11T16:30:28.410 回答