Page 1 of 1

Simple Logout Session link

Posted: Fri Jul 05, 2002 11:45 am
by fariquzeli
What's the easiest and best way to create a simple link that ends the session and logs the user out?

Posted: Fri Jul 05, 2002 11:48 am
by honkyinc
I always had a logout.php page that logged the user out, then redirected to my index.php page.

Code: Select all

<?php

session_destroy();
header("Location: index.php");

?>

Posted: Fri Jul 05, 2002 11:56 am
by fariquzeli
thanks, that's how i had it setup, just wanted to make sure it was adequote. :)

Posted: Fri Jul 05, 2002 12:32 pm
by RandomEngy
Actually:

Code: Select all

<?php

session_start();
session_destroy();
header("Location: index.php");

?>
If the session isn't continued first, PHP won't know what session to destroy, and it won't work. I've tested this myself.