0

I am working with php sessions and user accounts. When they click on the Log Out link on a page it generates the code in logout.php which is...

<? 
session_start();
session_destroy();
Header( “Location: http://www.espn.com” );
?>

The page destroys the session and for some reason it just goes back to the index.php page. I want to have it so that when the user is log out they are redirected to the page THEY WERE JUST ON logged out. I think I need to just change the code in my logout.php but I don't know what to do. I tried testing it by taking the user to espn.com but this didn't even work. Can someone help me set it up so that the user is sent to the page they were just on. Live Long and Prosper.

John Doe
  • 1,950
  • 9
  • 32
  • 53
  • this seems legit. should work. show me more of the php as well as the html where this is invoked. – Dan Kanze Jul 10 '12 at 02:22
  • Pablo functions are case-insentitive in php http://stackoverflow.com/questions/5643496/are-php-functions-case-sensitive – Dan Kanze Jul 10 '12 at 02:23
  • This isn't what I want. It is just an example. I want to redirect to the previous page the user was on not espn.com – John Doe Jul 10 '12 at 02:24

3 Answers3

3
Header( “Location: http://www.espn.com” );

Should be

header("Location: http://www.espn.com"); //<--NOTE: You are using wrong quotes!

PS: Although php functions are case insensitive, but you'd better use the low case head same with manual.

Update: If you want to redirect to the previous page, you could do:

if (!empty($_SERVER['HTTP_REFERER'])) {
    header("Location: ".$_SERVER['HTTP_REFERER']);
} else {
    header("Location: http://www.espn.com");
}
exit;
xdazz
  • 158,678
  • 38
  • 247
  • 274
0

Use:

header("Location: ".$_SERVER['HTTP_REFERER']);
0

You can access the previous page using:

$_SERVER['HTTP_REFERER'];

So if you set the your header location to that address, it should send the user back to the previous page

header('Location: '.$_SERVER['HTTP_REFERER']);

Although be warned that $_SERVER['HTTP_REFERER'] may be empty, you should check for this first and if it is empty send them elsewhere, like your homepage.

quinnjn
  • 623
  • 7
  • 10