Hostxpeed
Login Get Started →
Troubleshooting

Fix PHP "Headers Already Sent"

4 min read
43 views
Jun 10, 2026

Understanding the Error

Warning: Cannot modify header information - headers already sent

Output was sent before header() or session_start().

Find the Problem

The error message shows filename and line number:

Warning: Cannot modify header information - headers already sent by (output started at /path/to/file.php:12)

Check line 12 of that file for any output.

Common Causes

1. Whitespace Before <?php

// Wrong:
<space><?php

// Correct:
<?php

2. Whitespace After ?>

// Remove closing tag entirely (best practice)
// Or ensure no spaces after ?>

3. BOM (Byte Order Mark) in UTF-8 Files

Save files as "UTF-8 without BOM" in your editor.

4. echo/print Before header()

// Wrong
echo "Hello";
header('Location: page.php');

// Correct
header('Location: page.php');
exit;
// Then HTML

5. Error Messages as Output

Enable output buffering as temporary fix:

ob_start();  // At top of script

Fix WordPress Headers Already Sent

# Check wp-config.php for spaces before <?php
# Check functions.php in theme
# Disable plugins one by one

Prevention Tips

  • Omit closing ?> in pure PHP files
  • Use MVC pattern with output buffering
  • Set headers early in execution flow

Was this article helpful?