The solution Can not add header information - headers already sent

Bug fix this is simple.
Often, the same message appears at the start of the sessions in slightly different wording:
Warning: Cannot send session cookie - headers already sent Warning: Cannot send session cache limiter - headers already sent
For starters learn how to do the browser communicates with the server. There is a special protocol the header (), setcookie , session_start() , send HTTP headers.

We now consider this warning.
Warning: Cannot add header information - headers already sent by (output started at /www/script.php:5) on line 20
Cannot add header information - headers already sent . Everything is clearly written. "Can not send the header, the train has already left," - writes to us PHP. Next PHP reports in which the script and what his line ( output started at /www/script.php:5 ) concluded there was information that caused the automatic sending headers. Very easy to find and fix. Maybe there html tags can be the echo, or may simply not noticed the empty string or a space before the first tag <? .
Very often, this error causes the file connected via include , where either there is some conclusion, or a blank line after the closing PHP tag - it is very difficult to detect.

To solve this problem you need to function header () (or session_start (), setcookie ) and all the logic that it is, to put before any output to the browser. Just move higher in the script.
After all, you will still redirect the browser. That is, no text still will not be displayed! Hence, the output is something simultaneously with the Location header does not make sense. Properly plan the structure of your script: a block that handles the POST, should not output anything to the browser.

Sometimes you have checked everything - there is nothing anywhere. Change the editor. Look at your file in another program. For example, Windows Notepad by using Unicode encoding added to the top of your file special character Byte Order Mark, in any way without putting you to know. Open the script in another editor and remove extraneous characters. And change to another editor Notepad.

Numerous questions on the forum make me make an important point here:
This error does not appear from what you have in the script, "what is written above." And what PHP takes something in the browser. This does not necessarily code. This can be an error message. It may be blank or html tag. Yes Yes. For the most talented: it is about any symbols sent to the browser, not just those that the browser displays an inexperienced user. In HTML pages have the source code. And he is the result of the PHP script, not the beautiful bukovki with kartinochku as think a very large number of people.

by phpfaq.ru