Justkez

Trying to be a consistent blog 
« Back to blog

CakePHP Cannot modify header information

I have just spent too long trying to discover why a controller throws a "Cannot modify header information - headers already sent by..." error message. There's no obvious reason why, and no obvious fix. The controller works fine on another installation of Apache2 and PHP, but not on my machine at home.

The problem? White space after the closing ?> PHP tag. You can have as many carriage returns as you like, but don't try a space. Turns out it was reported here 9 months ago. The team's response is perfectly acceptable, but it's quite a hard little caveat to track down and fix! Here's hoping this will be of use to someone else in distress.

Comments (5)

Apr 29, 2010
aboxy said...
You have no idea how much time you saved me.had been struggling for over 2 hours and fix was simple;just as your mentioned.
Thanks a bunch.
May 04, 2010
Rosh said...
Just saved me a BIG headache!! Thanks!
May 04, 2010
Rizkee said...
Thank you...this info really helped me....
May 21, 2010
Simon said...
OMG...just spent hours looking for the d*** whitespace, and had the controller that had it open the entire time, but it was just lost in the widget madnes.

Anyways...thx, now i can die happy x)

Jul 23, 2010
Denis said...
THANKS man, you saved me!

Leave a comment...

 
Got an account with one of these? Login here, or just enter your comment below.
Posterous-login    twitter