Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session unset, or session_destroy? [duplicate]

Tags:

php

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 time the session has to accessed rather than recreated?

like image 896
Basic Avatar asked Apr 18 '11 01:04

Basic


People also ask

What is difference between Session_unset and session_destroy?

session_destroy() function: It destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. session_unset() function: It deletes only the variables from session and session still exists. Only data is truncated.

How do I unset and destroy a session?

A PHP session can be destroyed by session_destroy() function. This function does not need any argument and a single call can destroy all the session variables. If you want to destroy a single session variable then you can use unset() function to unset a session variable.

Which function is use to unset all sessions?

session_unset just remove all session variables.


2 Answers

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. 
like image 53
Mike Lewis Avatar answered Oct 09 '22 10:10

Mike Lewis


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().

like image 44
Marcel Avatar answered Oct 09 '22 09:10

Marcel