session_start(); // Must start a session before destroying it
if (isset($_SESSION))
{
unset($_SESSION);
session_unset();
session_destroy();
}
當用戶從菜單中選擇
Log out
,但不會放棄他的瀏覽器?我想徹底刪除會話的所有生存和$_SESSION
session_start(); // Must start a session before destroying it
if (isset($_SESSION))
{
unset($_SESSION);
session_unset();
session_destroy();
}
當用戶從菜單中選擇
Log out
,但不會放棄他的瀏覽器?我想徹底刪除會話的所有生存和$_SESSION
按照manual,還有更多的工作要做:
爲了完全終止會話,想註銷用戶,會話ID也必須取消設置。如果使用cookie傳播會話標識(默認行爲),則必須刪除會話cookie。 setcookie()可用於此目的。
手動鏈接有一個完整的工作示例如何做到這一點。從那裏偷來的:
<?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();
?>
我不會'未設置($ _ SESSION);''之前session_destroy()',它可能是session_destroy無法正常工作 – 2010-10-16 09:21:30