PHP - session_unset 是否取消注册 $_SESSION 变量? [英] PHP - Does session_unset unregister $_SESSION vars?
问题描述
session_unset() 是否会取消注册所有 $_SESSION 变量,或者您是否必须使用 unset()<手动清除注册到 $_SESSION 数组中的每个变量/a> ?
Does session_unset() unregister all the $_SESSION vars, or do you have to manually clear each variable registered into the $_SESSION array with unset() ?
我对此感到困惑,因为 PHP 文档说:
I'm confused about this because the PHP documentation says:
仅对不使用 $_SESSION 的旧弃用代码使用 session_unset().
Only use session_unset() for older deprecated code that does not use $_SESSION.
如果使用 $_SESSION,则使用 unset() 注销会话变量
If $_SESSION is used, use unset() to unregister a session variable
推荐答案
是的,它会删除所有会话变量.
Yes it removes all sessions vars.
session_unset — 释放所有会话变量
session_unset — Free all session variables
要删除所有会话变量,您还可以使用:
To remove all session vars, you can also use:
session_destroy();
有时即使同时使用 session_unset 和 session_destroy,您也可能会遇到问题.您必须清除 $_SESSION 数组.
Sometimes you might have problems even if using both session_unset and session_destroy. You have to clear $_SESSION array.
session_unset();
session_destroy();
$_SESSION = array();
这篇关于PHP - session_unset 是否取消注册 $_SESSION 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!