-4

Possible Duplicate:
PHP session start “Cannot send session cookie and cache limiter”

So I have been developing on my localhost, and I uploaded it to my actual web server finally, and kept getting messages saying:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

Even though session_start() was at the top, no white space, etc...

So I did some googling, and the only way to get it to work properly was to put this at the very top:

ob_start("ob_gzhandler");

What does that exactly do? Is it related to my error.

Community
  • 1
  • 1
Ryan Frank
  • 13
  • 3
  • locally my login work script worked fine, etc... this host gator server is really making me put this ob_start("ob_gzhandler"); wherever i use sessions and it's annoying. there's gotta be a different way. – Ryan Frank Oct 10 '11 at 09:32
  • Frankly you just omitted the interesting part of the error message: The location of the code that caused this error. – Gumbo Oct 10 '11 at 17:18

2 Answers2

1

Check for BOM at the start of your documents, this what probably causes the output before the session_start(); (Most text editors have a way to save your document without BOM; In Notepad++ you go to Encoding->Encode in UTF-8 without BOM).

Dvir
  • 5,049
  • 1
  • 23
  • 32
  • any idea about eclipse (with aptana studio integrated) – Ryan Frank Oct 10 '11 at 09:36
  • 1
    @Ryan Frank: Eclipse normally stores w/o BOM. Save the file under a second name, delete the old file, renamed the new file to the old filename. – hakre Oct 10 '11 at 09:41
  • @ RyanFrank: try exactly what @hakre said. Eclipse should store it without BOM, but sometimes you load a project that was saved by another text editor that put in the BOM. – Dvir Oct 10 '11 at 09:45
  • I did, it still says: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ryan/public_html/demo/classes/Auth.php:1) in /home/ryan/public_html/demo/classes/Auth.php on line 3.... My Auth.php file starts off with a session_start(); though – Ryan Frank Oct 10 '11 at 10:00
  • did you try opening the file with notepad++ and saving it without the BOM? – Dvir Oct 10 '11 at 14:27
  • yeah I deleted the file and saved it in another editors and it still doesn't work... Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ryan/public_html/demo/classes/Auth.php:1) in /home/gerbera/public_html/demo/classes/Auth.php on line 3 I'm reading Auth.php directly and running that file directly and after – Ryan Frank Oct 10 '11 at 19:42
1

and kept getting messages saying: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent

This is your first fault. You have just omitted the most important part of the error message, playnly saying, where the problem code is. Did you try to read it through?

and the only way to get it to work properly was to put this at the very top: ob_start("ob_gzhandler");

This is your second fault. ob_start is not the only and not the way to go.

The only proper solution is

  1. To read the error message and locate the place where output actually started.
  2. Fix your code to make it send HTTP headers before any output.
  3. Check for the possible Byte Order Mark at the beginning of your files and eliminate it.

php session weird error

This is your third fault. One cannot call "weird" an error which has been asked a zillion times already. I'd rather call it "extremely familiar and boring" one.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ryan/public_html/demo/classes/Auth.php:1) in /home/gerbera/public_html/demo/classes/Auth.php on line 3 I'm reading Auth.php directly and running that file directly and after – Ryan Frank Oct 10 '11 at 19:41