2

I have this code for my logout.php:

<?php

session_start();

$_SESSION = array();

if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
    $params["path"], $params["domain"],
    $params["secure"], $params["httponly"]
);
}

session_destroy();
    header( "Location: index.php" ); //to redirect back after logging out
?>

Problem is that the header doesn't work. I don't know if it has anything to do with the code above.. but I don't think so, cause it works on localhost - wamp server. Is it then because of the server I'm using? Or is it something wrong in the code?

Thanks!

Alina Gabriela
  • 121
  • 1
  • 11

3 Answers3

0

It's because of the Header Redirect needs the data Buffering to be on, It's Probably disabled on the server, Try to add ob_start(); After you session_start();

ImadBakir
  • 553
  • 1
  • 7
  • 26
0

Try it:

header( "Location: http://hostname.com/full_path/index.php" );

Or if are getting the error in using the header then try this code:

echo "<script>window.location.href='http://hostname.com/full_path/index.php'</script>";
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
  • 1
    Thanks, I tried the full path before - no result. Now I tried the second suggestion - works on my local host, but not on my domain.. so my guess is that is has something to do with the server – Alina Gabriela Feb 26 '13 at 11:37
0

Try this perhaps it works:

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">';    
exit; 
ImadBakir
  • 553
  • 1
  • 7
  • 26