【发布时间】:2018-06-01 20:03:32
【问题描述】:
我的 PHP 会话似乎没有动摇。当我单击注销后返回主页时,如果我再次刷新页面,那么它似乎让我重新登录......好像会话从未真正结束。如果我离开页面并重新访问它,也会发生同样的情况。这是我的 logout.php 页面:
<?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();
header("Location: index.php");
?>
我真的不知道它为什么要这样做,任何帮助肯定会得到赞赏。如果您需要更多信息,我很乐意提供一些信息。谢谢!
【问题讨论】:
-
在
session_destroy()之前致电session_unset() -
php.net/manual/en/function.session-destroy.php 最近,我发现实际上阅读我使用的功能的手册页非常有趣。即使是我习惯的功能,我也可以学习新事物。目前,在前几段中清楚地写了您必须取消设置会话才能真正销毁它:)
-
@Félix Gagnon-Grenier:OP 使用文档中的确切代码。您可能还会发现不仅阅读文档而且阅读问题也很有趣!
-
是的,我遵循了文档中的代码。我不知道为什么它不起作用......但目前我的 chrome 似乎是一个问题,因为在下载 Firefox 并对其进行测试后它可以工作!虽然,话虽如此,但它在我手机上的 Chrome 上不起作用,所以我不知道发生了什么。
-
Chrome != firefox != mobile :)