Thursday, 15 February 2007

PHP Destroying the current session completely

Here is a code snipper I got out from Janet Valade's PHP & MySQL Visual Blueprint book and this is what I use it to implement logout pages
session_start();
$_SESSION = array();
if (isset($_COOKIE['PHPSESSID']))
    setcookie('PHPSESSID', '', time() - 42000, '/');
session_destroy();

$return_url = 'login.php';
header("Location: http://".$_SERVER['HTTP_HOST']
                      .dirname($_SERVER['PHP_SELF'])
                      ."/".$return_url);
exit;

No comments:

Post a Comment

I have had so many good people trying to promote various community oriented sites through here. Therefore all comments will first have to come through me... so I get a chance to learn about the interesting sites before you do ...