2012-08-10 118 views
1

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

任何想法?

回答

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(); 
+0

哇。这就是诀窍!谢谢!将在8分钟内接受旅游回答。 – ljpv14 2012-08-10 03:17:43