2013-04-22 99 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."; 
    ?>