gpt4 book ai didi

php - 完全销毁 session 的最佳方法 - 即使浏览器未关闭

转载 作者:IT王子 更新时间:2023-10-29 01:10:12 24 4
gpt4 key购买 nike

够不够

session_start();   //  Must start a session before destroying it

if (isset($_SESSION))
{
unset($_SESSION);
session_unset();
session_destroy();
}

当用户从菜单中选择注销,但没有退出浏览器时?我想完全删除所有存在的 session 和 $_SESSION

最佳答案

根据manual ,还有更多工作要做:

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.

手动链接有一个关于如何做到这一点的完整工作示例。从那里偷来的:

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

关于php - 完全销毁 session 的最佳方法 - 即使浏览器未关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3948230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com