0

I have done a page that can only be accessed after a login. Now I have done a logout button, which works, but I get after logging out an error message. The redirection works after two seconds, the session ends, but I still get the following error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/u200098000/public_html/logout.php:2) in /home/u200098000/public_html/logout.php on line 3

This is my code:

<?php
 session_start();
 session_destroy();


echo "<h1>You succesfully logged out</h1>";
echo '<p> If you are not redirected automatically please click <a href="index.html">here</p>';

echo '<script>';

echo 'redirectTime = "2000";';
echo 'redirectURL = "/index.html";';
echo 'setTimeout("window.location = redirectURL",redirectTime);';

echo '</script>';


?>

Thanks a lot for any help.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
user3013909
  • 89
  • 3
  • 9
  • 2
    Remove **whitespace** in the beginning of your code, also in the beginnings of any file included. – Leonardo Dec 16 '13 at 18:09
  • http://stackoverflow.com/questions/8812754/cannot-send-session-cache-limiter-headers-already-sent the accepted answer is about not sending anything to the browser before starting session. (like echoing something) – Félix Adriyel Gagnon-Grenier Dec 16 '13 at 18:09

2 Answers2

1

Headers already sent generally means some kind of output has occurred before the session was started. Check for any files that have any kind of white space and make sure that you haven't done any print, echo, etc. commands before calling session_start(). Even trailing white space at the beginning or end of an included file can cause this to happen. One that bit me many moons ago was a single empty line at the bottom of an included file after the closing ?> PHP tag.

Crackertastic
  • 4,958
  • 2
  • 30
  • 37
0

To use cookie-based sessions, session_start() must be called before outputing anything to the browser.

Make sure you have nothing that outputs to the browser before those lines and delete any unessasary whitespace from that code up. That error means you outputted something to the browser

Krish R
  • 22,583
  • 7
  • 50
  • 59