# Warning: session_start(): Session cannot be started after headers have already been sent

**Code:** `session_start()` · **Category:** PHP · **Seen on:** PHP

session_start() ran after output was sent, so PHP can’t set the session cookie.

## Meaning

Sessions need a cookie header, and headers must be sent before any output. A BOM, whitespace before `<?php`, or an echo/warning earlier in the request causes it.

## Common causes

- HTML or whitespace before session_start()
- UTF-8 BOM in an included file
- A PHP notice printed earlier
- session_start() called inside a template

## Quick fix

1. Call session_start() at the very top of the entry script
2. Remove whitespace/BOM before `<?php` and closing `?>` tags
3. Turn display_errors off in production

## Detailed fix by platform

### PHP

1. Move `session_start()` into your bootstrap file included first by every page

## How to diagnose

1. **Output start** — The warning names the file/line where output started
2. **Order** — Is session_start() the first thing that runs?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/php/session-start-headers-already-sent)
