Cannot send session cookie ....
While working on a site last night I got this error when I uploaded the latest version of my code to the live server: Warning: session_start(): Cannot send session cookie – headers already sent …
Now, my first reaction was WTF! as I wasn’t seeing this on my development box. I was using the Apache Friends XAMPP product to run a WAMP install on my local windows XP machine so I guess there are some differences in the way apache works on win32 and linux.
Anyway, the Cannot send session cookie error is usually caused by outputting something to the client and then trying to send a cookie/write to the headers. So I start looking through my included files, trying to find a stray debug line or something like that. Nothing.
Ok, its late and no one will probably notice, but I have to find the problem.
Bang head on table a few times.
Ok, start again.
And then I see it. I had tabbed all of the source in one of my include files. Including the opening < ?php line! So, I was effectively sending a tab to output then processing my php.
More head slapping. General relief etc.
So there you go. If you ever have that problem and can’t see where its coming from, save yourself some wear and tear on the ole forehead and check for whitespace at the beginning of your source files.