Warning: Cannot modify header information - headers already sent
You called header(), setcookie() or session_start() after output had already been sent to the browser.
Meaning
HTTP headers must come before the body. Any output — even a single space before <?php, a BOM, or an echoed warning — flushes headers. The message tells you exactly where output started: “output started at /path/file.php:12”.
Common causes
- Whitespace or blank lines before
<?phpor after a closing?> - UTF-8 BOM at the start of a file
echo/HTML beforeheader()redirect- PHP notices/warnings printed before headers
⚡ Quick fix
- Open the file/line in “output started at…” and remove the output
- Omit closing
?>in pure-PHP files - Save files as UTF-8 without BOM
- Do redirects/cookies before rendering any HTML
Detailed fix by platform
PHP
- As a last resort
ob_start()at the very top buffers output, but fix the real cause.
Code examples
Output before header() — and the fix
php
<?php
echo '<p>Saving…</p>'; // ❌ output already sent
header('Location: /done.php'); // Warning: Cannot modify header information
<?php
saveOrder($data); // ✅ do the work and redirect first
header('Location: /done.php');
exit;Find a BOM or whitespace before <?php
bash
head -c 3 config.php | xxd # "efbb bf" at the start = UTF-8 BOM
grep -rlI $'^\xEF\xBB\xBF' --include=*.php .Re-save those files as "UTF-8 without BOM" and drop closing ?> tags in pure PHP files.
How to diagnose
- Output start — Which file:line does the warning name?
- Encoding — BOM present?
- Order — Is header() called after HTML?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026