session_start() PHP Origin: Application & API Last updated 14 Oct 2026

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.

Exact message you may see Session cannot be started after headers have already been sentsession_start(): Cannot start session
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 not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

100 — HTTP 100 Continue (HTTP)100103 — HTTP 103 Early Hints (HTTP)1031040 — Cloudflare Error 1040 / 1041: Invalid request header modification (Cloudflare)1040401 — HTTP 401 Unauthorized (HTTP)401411 — HTTP 411 Length Required (HTTP)411416 — HTTP 416 Range Not Satisfiable (HTTP)416BOM output — Unexpected characters at the top of the page / headers already sent by BOM (PHP)BOM outputCORS — CORS Error: No 'Access-Control-Allow-Origin' header is present (API)CORSsession_s…

Explore the map of this error Full error map →

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

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.