Wednesday, September 9, 2009

Handling "headers already sent" Error


We used to get below error when using header() in our php code.


Warning: Cannot modify header information - headers already sent by (output started at...


The reason/root cause for this warning is due the fact "No other information can be sent to the server before the Header".

This "headers already sent" error is usually caused by having white space before or after the opening and closing PHP tags (<?php . . . ?>).

So, remove any white space before or after these tags.


If you still get this error even after removing white space, you need to check whether you put echo of any text before using header().

Use of ob_start() at start of the code may resolve this issue.


More Articles...

No comments:

Search This Blog