Error Reference › PHP
PHP
Headers already sent (PHP)
Something already sent output to the browser, so PHP can't set headers/cookies/redirects anymore.
What it looks like
Warning: Cannot modify header information - headers already sent by (output started at /var/www/app/config.php:1) in /var/www/app/login.php on line 15
What does "Headers already sent (PHP)" mean?
A warning raised when code calls header(), setcookie() or session_start() after output has begun. The key part is in brackets: “output started at file:line” names exactly what sent the first byte.
What causes "Headers already sent (PHP)"?
- Whitespace or text before the opening PHP tag (or after the closing one).
- A BOM at the start of the file.
- An echo/var_dump before header()/setcookie().
How do I confirm the cause?
- Open the file and line given after “output started at” — that is where the stray output is.
- Look for blank lines or spaces before <?php, or after a closing ?> at the end of an included file.
- Check the file for a UTF-8 BOM (an invisible marker some editors add); re-save it as UTF-8 without BOM.
How do I fix "Headers already sent (PHP)"?
- Remove any output (incl. blank lines/BOM) before the header call.
- Don't add a closing PHP tag at the end of pure-PHP files.
- The error names the file:line that sent output first.
How do I stop it happening again?
- Leave out the closing ?> tag at the end of files that contain only PHP.
- Set your editor to save files as UTF-8 without BOM.