PHP:在尝试销毁它之前,是否需要检查$ _SESSION是否存在? [重复]
This question already has an answer here:
EDIT: Sorry about the title- I meant "before I attempt to unset it".
I want to destroy a specific session cookie, so I do so like:
unset($_SESSION['name']);
...but the user may or may not have that session set. So, should I be checking to see if it exists first, or does unset()
take care of that for me without errors?
if (isset($_SESSION['name'])) {
unset($_SESSION['name']);
}
</div>
此问题已经存在 这里有一个答案: p>
-
在PHP中取消设置之前检查var是否存在?
5 answers
span>
li>
ul>
div>
编辑:对标题感到抱歉 - 我的意思是“在我尝试取消设置之前 它是“。 p>
我想销毁一个特定的会话cookie,所以我这样做: p>
unset($ _ SESSION ['name ']); code> pre>
...但是用户可能会也可能不会设置该会话。 那么,我应该先检查它是否存在,还是
unset() code>为我做的没有错误? p>
if( isset($ _ SESSION ['name'])){ unset($ _ SESSION ['name']); } code> pre> div>
I think it doesn't matter whether you had to check it.Because whether you check it,the session will be unset and the unset function won't return any error.