开发者

Session unset, or session_destroy? [duplicate]

开发者 https://www.devze.com 2023-02-25 06:34 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: What is the difference between session_unset() and session_destroy() in PHP?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

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

What is the best for security, and if the session is unset are load times better the next t开发者_运维技巧ime the session has to accessed rather than recreated?


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

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.


Something to be aware of, the $_SESSION variables 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 $_SESSION superglobal so only do this when you're destroying a session.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消