php 会话未设置,或 session_destroy?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5697822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:15:37  来源:igfitidea点击:

Session unset, or session_destroy?

php

提问by Basic

Possible Duplicate:
What is the difference between session_unset() and session_destroy() in PHP?

可能的重复:
PHP 中的 session_unset() 和 session_destroy() 有什么区别?

What is the best for security, and if the session is unset are load times better the next time the session has to accessed rather than recreated?

什么是最好的安全性,如果会话未设置,下次访问而不是重新创建会话时加载时间会更好吗?

回答by Mike Lewis

Unset will destroy a particular session variable whereas session_destroy()will destroy all the session data for that user.

Unset 将销毁特定的会话变量,而session_destroy()将销毁该用户的所有会话数据。

It really depends on your application as to which one you should use. Just keep the above in mind.

至于您应该使用哪一种,这实际上取决于您的应用程序。请记住以上几点。

unset($_SESSION['name']); // will delete just the name data

session_destroy(); // will delete ALL data associated with that user.

回答by Marcel

Something to be aware of, the $_SESSIONvariables are still set in the same page after calling session_destroy()where as this is not the case when using unset($_SESSION)or $_SESSION = array(). Also, unset($_SESSION)blows away the $_SESSIONsuperglobal so only do this when you're destroying a session.

需要注意的是,$_SESSION在调用session_destroy()where后变量仍设置在同一页面中,因为使用unset($_SESSION)or时情况并非如此$_SESSION = array()。此外,unset($_SESSION)吹走$_SESSION超全局,所以只有在您销毁会话时才这样做。

With all that said, it's best to do like the PHP docs has it in the first example for session_destroy().

综上所述,最好像 PHP 文档在第一个session_destroy().