Page 1 of 1

Logout of PHP session

Posted: Tue Oct 01, 2002 11:44 pm
by Zoram
How do you script the logout for a session?

Posted: Tue Oct 01, 2002 11:48 pm
by mr_griff

Code: Select all

<?php
session_start();
session_destroy();

//User is logged out now
?>

Posted: Wed Oct 02, 2002 1:17 am
by Takuma
or you could use

Code: Select all

<?php
unset($_SESSION);
?>
or

Code: Select all

<?php
session_unset();
session_destroy();
?>

Re: Logout of PHP session

Posted: Wed Oct 02, 2002 3:02 am
by twigletmac
Zoram wrote:How do you script the logout for a session?
It depends on how you set your session up in the first place and what version of PHP you have.

The old way (if you're using PHP 4.0.6 or lower):

Code: Select all

<?php

// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
// Unset all of the session variables.
session_unset();
// Finally, destroy the session.
session_destroy();

?>
Using $_SESSION (if you have PHP 4.1 or up):

Code: Select all

<?php

// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
// Unset all of the session variables.
$_SESSION = array();
// Finally, destroy the session.
session_destroy();

?>
Examples taken from the manual.

Mac