Moez:
HTML is sent via HTTP. An HTTP communication consists of two parts: a part containing headers and a part containing content. When an HTTP communcation takes place, either from the client to the server (a request) or from the server to the client (a response), the headers are sent, then a blank line, then the content.
The header part must be sent first -- it's part of the HTTP spec. If at any time your script produces content-type output (basically anything not in HTTP headers), PHP assumes you're finished sending headers. It then sends that required blank line, then your content. If you then try to send more headers, you have violated the HTTP spec, and PHP will complain about it.
Content output includes but is not limited to anything from a print, echo, or print_r statement, and anything (including blank lines) that appears outside a PHP script outside the "<?php...?>" tags.
Content also includes any error or warning messages PHP itself generates and outputs. If your script generates a warning before hitting some statement that generates HTTP headers, you will see two messages: the script warning, and then an error telling you that your script tried to output headers after content output had begun. In that case, fix the first problem, and the second one will likely go away, too.
There is a way around this limitation -- output buffering. PHP can be configured to collect all output and send it all at once. It's more resource intensive and slows down your script, but it allows you to issue header() statements at any time. For more information, please read
Want the best answers? Ask the best questions: TANSTAAFL!