Logout of PHP session
Moderator: General Moderators
Logout of PHP session
How do you script the logout for a session?
Code: Select all
<?php
session_start();
session_destroy();
//User is logged out now
?>or you could use
or
Code: Select all
<?php
unset($_SESSION);
?>Code: Select all
<?php
session_unset();
session_destroy();
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Re: Logout of PHP session
It depends on how you set your session up in the first place and what version of PHP you have.Zoram wrote:How do you script the logout for a session?
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();
?>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();
?>Mac