gpt4 book ai didi

php - 无法结束 PHP session

转载 作者:搜寻专家 更新时间:2023-10-31 20:41:19 26 4
gpt4 key购买 nike

好的,所以我有以下代码来回显我已经设置的一些 session 变量。(它们像预期的那样回显。)

(索引.php)

<?php session_start();?>
Username: <?php echo $_SESSION['username']; ?><br>
Password(encrypted): <?php echo $_SESSION['password']; ?><br>
ThemeColor: <?php echo $_SESSION['themecolor']; ?><br>


我有这段代码,我试图用它来结束 session ,但是当我运行上面的代码时,变量仍然回显,所以 session 仍然有效

(注销.php)

<?php
session_start();
session_unset();
session_destroy();
?>


你能告诉我我做错了什么吗?

最佳答案

直接来自 PHP documentation :

<?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 - 无法结束 PHP session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20905679/

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