释放会话变量



在我们的网站中,我们应用了很多会话变量。设置完成后,我们将取消设置以释放服务器资源。

除了逐个取消设置每个会话之外,是否有任何功能可以检查一个网站的会话变量尚未被取消设置?

谢谢。

要取消单个记录,请使用

unset($_SESSION['varname']);

清空整个会话,使用

session_destroy();

会话被自动删除,当它没有被访问一段时间(可通过php.ini配置)。因此,不需要自己删除孤立的会话数据。

这可以用session_destroy();

http://www.php.net/manual/en/function.session-destroy.php

你需要session_destroy();

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

也取消设置由会话创建的cookie !

最新更新