Cannot send session cache limiter
An often asked (PHP) question in the CakePHP IRC channel is how to fix the problem which causes the following warning:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/dho/projects/test/trunk/app/controllers/users_controller.php:7) in /home/dho/projects/cake_1.2.x.x/cake/libs/session.php on line 131
It is a bit nasty. The warning points us to line 7 (the last line). Hm, but line 7 looks correct, doesn’t it?
<?php
class UsersController extends AppController {
var $uses = null;
function edit() {}
}
?>
Well, if you mark line 7 with your mouse, you see that there is a space after the “>” character. And this space is the cause of the warning. If you remove the space, the warning disappears.




This happened to me just yesterday!
tricky!
Thanx for the warning!
Another solution is not to use the php end tag ever….
@Tarique Sani: Yes, that is another solution. But personally I don’t like it as it looks like something is missing ;-)
@cakebaker: I perfer being meticulous as well but something miising is better than something amiss ;)
the best is just clean code.
this is one of the most common problems for newbies (and very oftenly occuring situations for any php-dev in general)
but even the best solution is extremely simple, so i really don’t see why anyone would do such things as omitting php closing tags (except for being a crappy programmer)
Dieter
@Dieter: Nowhere is it stated that closing tag is a must have in scripts which have just PHP code, thus calling the practice omitting the closing tags as crappy programming is just a personal opinion rather than a stated best solution or best practice. This is similar to why you cannot see anyone would do such a thing - it is your limitation…
P.S. Are trying to flame me ;)
I have this problem but cannot fix it!
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\……\index.php:9) in C:\…….\index.php on line 28
but on line 9 i have:
there are no extra spaces!!! i have checked the very last line of code and very first. there was blank spaces, but i got rid of those, still no result. what is the matter? I had this error twice, but once disappeared when I moved my “include” code before session_start(). any ideas?
Fixed the error!!! I did not have session_start() at the top of my code. I had it in the HTML area after . i hope this helps someone!!! :)
@tork: I am glad you could solve your problem.
Thanks!
Wasted 2 or 3 hours of programming thanks to two little spaces. Won’t happen again though :)
jdub
@jdub: I think this is an experience every PHP developer has to make once in his life ;-)
I did it…too! :D
cheers & thx a lot
carsten
thanks, weird. happened to me in a few of my models during a clean server move.
to be serious, I almost expected it was something weird like this - and was really surprised when I tabbed back to this window and saw it was what I had expected, but not seriously enough to even consider looking at myself. So .. nice, thank you :)
Thanks so much!! That error was almost driving me crazy! wasted a whole day over it… Thanks a million! :-)
@SJ: I am glad this article helped you :)
thanks very much. you help me very good
be alive
@hosein: I am happy to hear that :)
Thank you so much. This bug drove me crazy for 2 days.
kynguyen: Yeah, it is nasty. Cool to hear this post helped you :)
This just happened to me!
Thank you for posting this…
It has totally reduced my stress level!
I now love this site!
:D
@Yahesel: Thank you :)
awesome thnx!
great help
3h wasted
thx for this post
WoW !, I Almost fight with this problem from 8.00 Am to 1.18PM And Now Able to solve it Thanks to you’r Site…I’m s Sinhalese and I Wish you in my language bro!
Budu Saranai Machan,
JAYAWEWA !!!
@Tharindu: Thanks, I am glad this article helped you :)