PHP Compilation of Errors and Warnings Warning: Cannot modify header information - headers already sent


Appearance :

Happens when your script tries to send a HTTP header to the client but there already was output before, which resulted in headers to be already sent to the client.

Possible Causes :

  1. Print, echo: Output from print and echo statements will terminate the opportunity to send HTTP headers. The application flow must be restructured to avoid that.

  2. Raw HTML areas: Unparsed HTML sections in a .php file are direct output as well. Script conditions that will trigger a header() call must be noted before any raw blocks.

    <!DOCTYPE html>
         // Too late for headers already.
  3. Whitespace before <?php for "script.php line 1" warnings: If the warning refers to output in line 1, then it's mostly leading whitespace, text or HTML before the opening <?php token.

    # There's a SINGLE space/newline before <? - Which already seals it.

Reference from SO answer by Mario