No output before sending headers
Functions that send/modify HTTP headers must be invoked before any output is made. Otherwise the call fails:
Warning: Cannot modify header information - headers already sent (output started at file:line)
Some functions modifying the HTTP header are:
- header / header_remove
- session_start / session_regenerate_id
- setcookie / setrawcookie
Output can be:
- Unintentional:
- Whitespace before
<?php
or after ?>
- UTF-8 Byte Order Mark
- Previous error messages or notices
- Intentional:
print
, echo
and other functions producing output (like var_dump
)
- Raw
<html>
areas before <?php
code.
Hint : for checking this, press crtl+u on the page to see the source, and check if the error is in line 2 , or there is a space before it.