0

I am trying to to understand why a simple logout.php script works on localhost but not on live server. Thanks in advance for any help.

here is the entire logout.php file

<?php//Start the session
session_start();

//Terminate the session
session_unset();
//Redirect users to login page
header('Location:  http://www.somewebsite.com/login');
exit(); 


?>
  • Are you on a shared host for the live server? Could be that the provider is restricting some PHP functions... **BTW:** Try adding `session_destroy();` after `session_unset();`. Read more about this [here](http://php.net/manual/de/function.session-unset.php#54731). – Markus Hofmann Jan 13 '14 at 21:51
  • Try to remove second space after "Location: " – dikirill Jan 13 '14 at 21:52
  • You should enable error reporting so you can at least be notified if there is something hindering your efforts. For testing purposes, put **error_reporting(E_ALL);** at the top of that page and try again. – Rottingham Jan 13 '14 at 21:53
  • I spoke with host provider, they are looking into. I thought to also post the issue here in case someone has seen this before. – user3001162 Jan 13 '14 at 21:53
  • Ok, also have a look at [**this**](http://php.net/manual/de/function.session-unset.php#107089). – Markus Hofmann Jan 13 '14 at 21:55
  • Rottingham thank you for your input. Here is what I got when I added the suggested code "error_reporting(E_ALL);" – user3001162 Jan 13 '14 at 21:57
  • Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /homepages/36/d451465821/htdocs/logout.php:2) in /homepages/36/d451465821/htdocs/logout.php on line 5 Warning: Cannot modify header information - headers already sent by (output started at /homepages/36/d451465821/htdocs/logout.php:2) in /homepages/36/d451465821/htdocs/logout.php on line 10 – user3001162 Jan 13 '14 at 21:57
  • Thanks Markus! I added session_destroy(); but no change. I am looking at the link you provid. Thanks again! – user3001162 Jan 13 '14 at 22:02
  • 1
    It might be that your PHP script is generating an error before you execute `header()` or you have a space, tab or newline before opening the ` – Jochem Kuijpers Jan 13 '14 at 22:17
  • @JochemKuijpers Seeing as `session_start()` is on line 5, I'd say they have 3 lines of non-php code – Phil Jan 13 '14 at 22:23
  • Jockem, Thank you very much! That seemed to solve the problem. I removed a newline before – user3001162 Jan 13 '14 at 22:25
  • @user3001162 Glad I could help, I've posted it as an answer to your question below. – Jochem Kuijpers Jan 13 '14 at 22:34

1 Answers1

0

As you mentioned in your comments, you had a newline in front of your <?php tag which caused output headers to be sent.

Resolve by removing the newline (or space, or tab, etc.)

Jochem Kuijpers
  • 1,770
  • 3
  • 17
  • 34