为什么 PHP session_destroy() 不起作用? [英] Why is PHP session_destroy() not working?
问题描述
我尝试使用 session_destroy()
方法销毁所有会话变量,但使用此方法后,值并未销毁.
I tried to destroy all session variable by using the session_destroy()
method, but after using this method, the values are not destroyed.
为什么 session_destroy()
不起作用?
有没有其他方法可以在 PHP 中销毁会话?
Is there any other way to destroy the session in PHP?
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800))
{
session_destroy();
session_unset();
}
推荐答案
使用session_destroy()
后,会话在后台被销毁.出于某种原因,这不会影响 $_SESSION
中的值,该值已经为此请求填充,但在以后的请求中它将为空.
After using session_destroy()
, the session is destroyed behind the scenes. For some reason this doesn't affect the values in $_SESSION
, which was already populated for this request, but it will be empty in future requests.
如果需要,您可以手动清除 $_SESSION
($_SESSION = [];
).
You can manually clear $_SESSION
if you so desire ($_SESSION = [];
).
这篇关于为什么 PHP session_destroy() 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!