“Cannot modify header information - headers already sent”

Fix the PHP headers already sent warning: stray whitespace, byte order marks and output before redirects or cookies.

Guide2 min readLast updated
On this page
  1. Does this match what you’re seeing?
  2. The message tells you where
  3. The usual causes
  4. Fixing it
  5. Editing tip
  6. If it doesn’t work
  7. Common questions

Does this match what you’re seeing?

  • Warning: Cannot modify header information - headers already sent by (output started at ...)
  • Redirects or logins stop working
  • The problem appeared after editing a PHP file
Warning: Cannot modify header information - headers already sent by (output started at /home/user/domains/yourdomain.co.uk/public_html/wp-config.php:1)

Headers — redirects, cookies, content type — must be sent before any page content. Something output content first, so the later header couldn’t be sent.

The message tells you where

”output started at ... wp-config.php:1” is the file and line that produced the early output. Go there, not to the file named at the start of the warning.

The usual causes

  1. Whitespace before <?php — a blank line or space at the very start of the file.
  2. Whitespace after a closing ?> at the end of a file. The fix is to delete the closing ?> entirely; it’s optional at the end of PHP files.
  3. A byte order mark (BOM) — an invisible character some editors add to UTF-8 files. Re-save as “UTF-8 without BOM”.
  4. echo, print or HTML before a header() or setcookie() call.

Fixing it

  1. Open the file named after “output started at” in a code editor (the File Manager editor works).
  2. Remove anything before <?php on line 1.
  3. Remove a closing ?> and anything after it at the end of the file.
  4. Save as UTF-8 without BOM.

Editing tip

Word processors and some basic editors add hidden characters. Use a code editor.

Choosing a host for a PHP project? Every Traxio account runs PHP 7.4 to 8.4 with a MySQL database: see PHP and MySQL hosting, £0.99 a month.

If it doesn’t work

These guides cover the most common problems, starting with what you can see. Or browse every fix for a common problem.

Common questions

What does “headers already sent” mean?

Your script tried to send a header — a redirect, a cookie — after output had already started. The usual culprit is a blank line or a stray space before the opening <?php tag in an included file. The error message names the file and line that produced the output.

Spotted something out of date or unclear? Tell us and we’ll fix it.

Keep going