Auto redirect on logout.php

Hi folks,
Just sorted out my login script and was wondering if there was anything that could sortout my logout file. That when the user hits the logout button it, automatical goes back to the index.php, i have it set to destroy the session var’s its just would look better that a

You are logged out please click here to go somewhere

Kind Regards


You can try using a meta refresh inside a function. This example has the meta refresh set to 3 seconds:

function redirect() {

echo "<meta http-equiv="refresh" content="3;URL=index.php">n";
echo "Please wait.....";


Put the function anywhere in your logout page, then simply call the function after you have reset the session:


Hope that helps.

Thanks for the quick reply, Could i use something like this and place it in a global file? will try it in my code now, but knowing my luck i’ve missed something lol

function redirect() {
echo “n”;
echo “You are not currently logged in, logout failed, Please wait…”;


/* Kill session variables */
$_SESSION = array(); // reset session array
session_destroy(); // destroy session.

 echo "<meta http-equiv="refresh" content="3;URL=index.php">n"; 
 echo "Please wait....."; 

}/* End Function

Should be ok, except if your variable $logged_in is declared outside the function you need to declare it as a global variable inside function

function redirect() {

global $logged_in;

//rest of code


Not that carella’s method won’t work, it will, but I prefer to use the header function.

I would use:

header("Location: path/to/index.php");

which I would put instead of:

echo "<meta http-equiv="refresh" content="3;URL=index.php">n"; echo "Please wait.....";

If you do use header() be aware that it must be called before any other output is sent.

Hasta later,

Thanks kammo.

I usually go with the meta refresh idea for beginners as they find it easier to use.

Sponsor our Newsletter | Privacy Policy | Terms of Service