# Warning: Cannot modify header information - headers already sent

**Code:** `Headers already sent` · **Category:** PHP · **Seen on:** PHP, WordPress

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 `<?php` or after a closing `?>`
- UTF-8 BOM at the start of a file
- `echo`/HTML before `header()` redirect
- PHP notices/warnings printed before headers

## Quick fix

1. Open the file/line in “output started at…” and remove the output
2. Omit closing `?>` in pure-PHP files
3. Save files as UTF-8 without BOM
4. Do redirects/cookies before rendering any HTML

## Detailed fix by platform

### PHP

1. 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

1. **Output start** — Which file:line does the warning name?
2. **Encoding** — BOM present?
3. **Order** — Is header() called after HTML?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/php/cannot-modify-header-information)
