-2

I'm having a little problem when I try to logout

    <?php
session_start();
session_unset();

session_destroy();
header("location:../");
?>

this is my logout code, and that is the error:

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

Warning: Cannot modify header information - headers already sent by (output started at /home1/jota/public_html/adm/logout.php:1) in /home1/jota/public_html/adm/logout.php on line 6

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126

2 Answers2

0

There appears to be some whitespace in front of your opening <?php tag. Remove it, so there is no characters before it, and it should work fine.

Alternatively, you could enable output caching by calling ob_start() at the start of your script, or by changing the output_buffering variable in your php.ini file to 1. (Note this will enable it for EVERY PHP file on your server -- you may wish to instead do it in a .htaccess file for the directory your code is in.)

Tristan
  • 3,058
  • 6
  • 40
  • 68
0

As @Wesley Murch said in his comment , you have a white space in the beginning of your page ,as in php documentation

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

You are outputing white spaces here.

Charaf JRA
  • 8,249
  • 1
  • 34
  • 44
  • No don't do the redirect in javascript. Besides, you'll still get the same error. The fix is simple: no output before headers. – Wesley Murch Sep 15 '13 at 17:30
  • `session_start()` and `session_destroy()` can also output headers, so your suggestion would not solve the root cause of this issue. Users may also have JavaScript disabled. – Tristan Sep 15 '13 at 17:30
  • @TristanSeifert i agree , ideleted the javascript part because session also output header – Charaf JRA Sep 15 '13 at 17:33
  • may be BOM issue. you really can't say whitespace for sure. – itachi Sep 15 '13 at 18:34