O boy… I’m in trouble now…
CakePHP project is probably the easiest project I’ve ever done in my life. Until I have to debug it…
Why all the sudden I got “Headers already sent… on session.php”?
Folks at Google Group had lots of talk about it. Most suggested that I have strange character or spaces before or after <?php ?> tag.
Nada… No such problem here in my code, double checked it three times.
Man, not even Google Group can help me this time.
Anyone of you kind souls out there willing to help this poor lad?
UPDATE:
Ahsan comments make me to double check my cake’s php files. It turns out that i have a SINGLE white space on my /app/webroot/index.php. Man… a single whitespace… This is why I shouldn’t do initial development on Windoze machine.
Hello didip,
make sure that there are no whitespaces before the first tag in all your controllers, default.thtml (thats the layout file), and possibly also in your model and view files. So, if you have a file like this:
the should be the last thing in your file.
Hope, I was useful.
There are many factors to errer “header already sent” but most common one is the whitespace. I’ve just fixed mine so just like to share how i went through incase someone come accross one like mine.
First, before writing cake, i thought this was ok..
Since in my sense, the whitespace b/w “}” and “?>” is still in PHP server-side tag and should not outputing anything,
but seems like cake do not except it.. it has to be:
Notice that now the } and ?> is now on the same line. So I went through and fix this in all my model and redirect/session is now back to work.
Tips:
For me only deleting the white space b/w } and ?> sometime still won’t work. I have to **delete and retype the whole thing**.
Don’t know why but it must be something to do with the encoding.
Hope that was helpful.
Cheers.
In case your file is encoded in UTF-8 make sure that the BOM part (Byte Order Mark) is not present.
I got to remove it to make my controller working
Thanks for the tip – saved me some nice time digging through code.
Cheers,
Mark
Can’t believe a single space would cause such a disaster.. Mine was not at the index.php but at a controller file. I would advice anyone to look VERY closely at the opening <?php tag and avoid entering any spaces after that. Thank you!!! this was a huge time saver.
Daniel.
Yep! had this same problem. It is almost certainly a whitespace issue. If you use Coda as your text editor there is a plugin that will remove whitespace from your document.
Note that this header error will also cause the SWXExplorer to give you a null object reference if you are using AmfPhp.
I hope this saves someone else time.
You have just save my day. Better yet, my week.