doujiao2014 2016-08-23 02:09
浏览 15
已采纳

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>
  • 写回答

1条回答 默认 最新

  • dpchen2004 2016-08-23 02:15
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?