session_start() 🐘 PHP

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

  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?

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