Warning: session_start(): Session cannot be started after headers have already been sent
session_start() ran after output was sent, so PHP can’t set the session cookie.
Seen on:
PHP
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
- Call session_start() at the very top of the entry script
- Remove whitespace/BOM before
<?phpand closing?>tags - Turn display_errors off in production
Detailed fix by platform
PHP
- Move
session_start()into your bootstrap file included first by every page
How to diagnose
- Output start — The warning names the file/line where output started
- Order — Is session_start() the first thing that runs?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026