为什么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屋!