PHP Warning: Cannot modify header information — headers already sent

Whitespace before `<?php`, UTF-8 BOM, or echoed debug output flushed HTTP headers early.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: PHP Warning Platform: PHP
Common Root Causes:
  • Whitespace before `<?php`, UTF-8 BOM, or echoed debug output flushed HTTP headers early.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Save PHP files as UTF-8 without BOM and omit closing `?>` tags in pure-PHP files.
Safe Diagnostic Command:
head -c 6 <file.php> | od -tx1
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Whitespace before `<?php`, UTF-8 BOM, or echoed debug output flushed HTTP headers early. Recommended diagnostic: `head -c 6 <file.php> | od -tx1`. Remediation: Save PHP files as UTF-8 without BOM and omit closing `?>` tags in pure-PHP files.

Worked Examples

  • Run `head -c 6 <file.php> | od -tx1` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-php-headers-already-sent · Independently verified: 2026-11-25

Related Resources