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();
?>

もう 1 つの参考資料として、George Brighton がコメントで言及したPHP Session Introductionがあります。

于 2013-09-11T16:14:01.110 に答える