Warning: Cannot modify header information
PHP Programming Language
Severity: ModerateWhat Does This Error Mean?
This warning means PHP tried to send an HTTP header — like a redirect or a cookie — but it was too late. HTTP headers must be sent before any output. Once PHP outputs even a single character — a space, a blank line, an echo — the headers are already sent and cannot be changed. The full message usually says: 'headers already sent by (output started at file.php:10)'.
Affected Models
- PHP 5.x
- PHP 7.x
- PHP 8.x
- All PHP versions
Common Causes
- An echo, print, or HTML block appears before header() or setcookie() is called
- A blank line or space exists before the opening <?php tag in a file
- A file saved with a BOM (Byte Order Mark) sends invisible characters before PHP runs
- session_start() is called after output has already been sent to the browser
- An error message or var_dump() earlier in the script produced output before the header call
How to Fix It
-
Move all header(), setcookie(), and session_start() calls to the very top of your PHP file — before any echo, print, or HTML output.
There must be absolutely no output before these calls. Even a single space counts as output.
-
Check every included file for output before the header calls. The output could be coming from any included or required file.
The error message tells you exactly where the output started — look at the file and line number in parentheses.
-
Open each PHP file in a hex editor or text editor with encoding support. Check that the file does not start with a BOM (Byte Order Mark).
A BOM is three invisible bytes at the start of a UTF-8 file. Save files as 'UTF-8 without BOM' in your editor.
-
Use output buffering as a workaround: add ob_start() at the very beginning of your script (before any output) and ob_end_flush() at the end.
Output buffering captures all output and sends it at once at the end, giving header() calls time to run first.
-
Make sure there is no blank line before the opening <?php tag and no blank line after the closing ?> tag (or remove the closing tag entirely).
A blank line outside PHP tags is treated as HTML output. Removing the closing ?> at the end of PHP-only files is a best practice.
When to Call a Professional
Headers already sent warnings are common in PHP development. They do not require professional help. If you are working with a CMS like WordPress and a plugin is causing this, report it to the plugin developer.
Frequently Asked Questions
What does 'output started at file.php:10' mean in the error?
PHP is telling you exactly where the first output happened. That file and line number is where something was printed to the browser before your header() call. Go to that line and remove the output, or move your header() call before it.
Does using ob_start() really fix this?
Yes — output buffering holds all output in memory instead of sending it to the browser. This gives you freedom to call header() and setcookie() even after some output. But it is a workaround. The cleaner fix is to call headers before any output.
Can a closing PHP tag ?> cause this error?
Yes. Any whitespace or newlines after ?> are sent as output. For files that contain only PHP code, it is best practice to omit the closing ?> tag entirely. This eliminates accidental trailing whitespace.