The functions that send and modify the HTTP headers must be invoked before any output is made, failing by which the call fails: Please note that a user cannot modify header information - headers already sent in which the output started at script:line
Some functions modifying the HTTP header are:
The Output can be Unintentional which includes the whitespace before <?php or after ?>, the UTF-8 Byte Order Mark specifically along with the previous error messages or notices. The Output can also be Intentional which includes print, echo and other functions producing output along with raw <html> sections prior <?php code. This occurs as the PHP scripts mainly generate HTML content, but also pass a set of HTTP/CGI headers to the webserver:
HTTP/1.1 200 OK
Powered-By: PHP/5.3.7
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
<html><head><title>PHP page output page</title></head>
<body><h1>Content</h1> <p>Some more output follows...</p>
and <a href="/"> <img src=internal-icon-delayed> </a>
The page/output always follows the headers. PHP has to pass the headers to the web server first. It can only do that once. After the double line break it can nevermore amend them.
When PHP receives the first output (print, echo, <html>) it will flush all collected headers. Afterward it can send all the output it wants. But sending further HTTP headers is impossible then.