Sunday, December 13, 2009

PHP error Warning: Cannot modify header information - headers already sent by ...

Error ...

PHP Warning: Cannot modify header information - headers already sent by.............

Hello PHP developers over there.This is a very frequent error or I will say an obvious error if you are new to PHP coding.It can occur due to many reasons such as:-

1. Headers must be parsed before any HTML,
2. Look for any statements that could send output to the user before this header statement. If you find one or more, find some way to move the header statement before them.
3.Make sure there is no white space outside of the php start and end tags. While a blank line before the 4.header("location:../first.php"); //'Location' should replace 'location'
5.fix your script to send the cookies at the correct time.
Solutions:-

Note: This Error irritates a lot.So if you are in a hurry go for Solution 3 and resume.:)
1.Try to resolve the above if exist.If the problem still persists..
2. Modify the PHP.ini file of your server by turning => output_buffering=on or output_buffering = 4096
3. Best Solution:

try placing this at the top of your page:
//Its turning on the output buffer.

then at the bottom of the page place this line of code:

//So any output is kept in the buffer.This is to flush the buffer.

No comments: