2013-04-22 113 views
3

我的註銷頁面不會損壞會話。我已經搜索並閱讀了相同的問題,但他們都沒有解決我的問題。註銷不會破壞會話

以下是我的登出頁面。請注意,我有兩塊php,因爲我有一個模板。

<?php 
    error_reporting(E_ALL^E_NOTICE); 
    session_start(); 
    $userid = $_SESSION['userid']; 
    $username = $_SESSION['username']; 
?> 
<?php 
    if($username && $userid) { 
    session_destroy(); 
    echo "You have been logged out.<a href='members.only.php'>My Logs.</a>"; 
    } 
    else 
    echo "You are not logged in."; 
?> 

正如我可以看到我登出後,我有一個鏈接到一個成員限制頁面,所以我可以檢查。但它仍然歡迎被登錄的最後一個用戶

+0

它不會給你任何的錯誤?使用ini_set('display_errors','On') – aleation 2013-04-22 12:01:26

+0

您是否收到「」您沒有登錄。「消息? – Shin 2013-04-22 12:01:58

回答

0

嘗試使用:

session_cache_limiter ('private_no_expire, must-revalidate'); 
4

請閱讀session_destroy文檔:

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.

這意味着,你應該做別的事情。例如:

$_SESSION = array();

2

session_destroy(),刪除所有與當前會話相關聯的數據。它不會取消設置與會話關聯的任何全局變量,也不會取消設置會話Cookie。要再次使用會話變量,必須調用session_start()。你可以閱讀更多關於它here

1

替換此session_destroy部分:

<?php 
     if($username && $userid) { 

    // 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(); 
    $_SESSION = array(); 
     echo "You have been logged out.<a href='members.only.php'>My Logs.</a>"; 
     } 
     else 
     echo "You are not logged in."; 
    ?>