"Cannot modify header information - headers already sent" in PHP — What It Means and How to Fix It
What the PHP error "Cannot modify header information - headers already sent" means and how to fix it.
Published November 1, 2026
This is the same 'headers already sent' problem, usually pointing at an included file that printed whitespace before PHP sent a header or started a session.
What it means and why it happens
The 'output started at' file and line tell you where stray output came from, often an included file with a blank line before <?php or after ?>.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
Warning: Cannot modify header information - headers already sent by (output started at /app/functions.php:1)
Practical examples
Code that triggers it
<?php
include 'functions.php'; // has a blank line before <?php
session_start();The fix
<?php
session_start(); // before any output
include 'functions.php';Find stray output
grep -rL --include=*.php '?>' . # files that don't close the tag (preferred)
head -c 3 file.php | xxd # detect a BOMCommon mistakes
- Not opening the file named in the message.
- Using closing ?> in pure PHP files.
- UTF-8 BOM from some editors.
Key takeaways
- Cannot modify header information: This is the same 'headers already sent' problem, usually pointing at an included file that printed whitespace before PHP sent a header or started a session.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Best practice?
Omit the closing ?> tag in files that contain only PHP.
How do I find which line caused Cannot modify header information?
The error message and stack trace show the file and line; start there and work backwards.