How do I Destroy Session?

thread: 5 messages  |  last: a year ago  |  started: sunday, february 7, 2010, 12:59 pm pst


#1  |  kingwithin (San Francisco, CA) United States of America
Sunday, February 7, 2010, 12:59 PM PST

I want a simple log out link that will “destroy session” as they do in ruby on rails.

How do I do that?
'

#2  |  VexedPanda (Calgary, AB) Canada
Monday, February 8, 2010, 8:00 AM PST

$_SESSION = array(); should do it.

#3  |  kentpachi (France, EU) France
Thursday, February 25, 2010, 12:22 AM PST

also session_destroy();
could make the job depending if you want to destroy all the session or specific keys
unset($_SESSION['key']) ;
$_SESSION['key'] = null ;


hth

#4  |  VexedPanda (Calgary, AB) Canada
Friday, February 26, 2010, 9:21 AM PST

session_destroy() actually prevents you from using the session any more until session_start() is called again, so this is probably overkill and may cause issues.

#5  |  Marshton (UK) United Kingdom
Monday, March 8, 2010, 11:05 PM PST

session_destroy(); is better if you are actually 'logging out a user' for them not to return (until they come back, that is), unset($_SESSION['meow']); is better for single session values.



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.