Logging out


Difficulty: Super easy

This is just something very quick and basic. Here is a logout code. I added in comments.

//That continues on the started session

//That destroyed the session

header(‘Refresh: 3; index.php’);
//That means that you will be redirected to the main page in 3 seconds

echo “Logged out. Redirecting in 3 seconds”;
//That should be straightforward


I know this is very basic.


If you are storing any information in your settings (like username, password, ID#) it’s could to unset those as well! Adding on to your code here:


$_SESSION = array();

header(‘Refresh: 3; index.php’);

echo “Logged out. Redirecting in 3 seconds”;



Not sure, but, shouldn’t you echo the 3 second notice before you header it out?
Don’t think it will be seen without using it before exiting…


I think your right as the refresh will show the message but the exit command will stop the script going any further, is it won’t get to the echo at all.