{
  "id": "php/session-header-already-sent-output-buffering",
  "signature": "Warning: session_start(): Cannot start session when headers already sent in /var/www/app/src/Controller/AuthController.php on line 23",
  "signature_zh": "警告：session_start()：当标头已发送时无法启动会话",
  "regex": "Warning: session_start\\(\\): Cannot start session when headers already sent",
  "domain": "php",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Output (e.g., whitespace, HTML, or BOM) was sent to the browser before session_start() was called, preventing PHP from setting session cookies or headers.",
  "root_cause_type": "generic",
  "root_cause_zh": "在调用 session_start() 之前，输出（例如空白、HTML 或 BOM）已发送到浏览器，阻止 PHP 设置会话 cookie 或标头。",
  "versions": [
    {
      "version": "PHP 8.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PHP 8.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PHP 8.3.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding ob_start() at the top of every script to buffer output",
      "why_fails": "This masks the issue and can cause memory bloat; it doesn't fix the root cause of premature output.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "Moving session_start() to the very end of the file",
      "why_fails": "Session must be started before any output; moving it later will still fail if there is output before it.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Enable output buffering in php.ini:\noutput_buffering = 4096\nThis buffers all output until the script ends, allowing headers to be sent later.",
      "success_rate": 0.85,
      "how": "Enable output buffering in php.ini:\noutput_buffering = 4096\nThis buffers all output until the script ends, allowing headers to be sent later.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Remove any whitespace or BOM before <?php in all included files, and ensure session_start() is called before any echo or HTML:\n<?php\nsession_start();\n// rest of code\n?>",
      "success_rate": 0.95,
      "how": "Remove any whitespace or BOM before <?php in all included files, and ensure session_start() is called before any echo or HTML:\n<?php\nsession_start();\n// rest of code\n?>",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在 php.ini 中启用输出缓冲：\noutput_buffering = 4096\n这会缓冲所有输出直到脚本结束，允许稍后发送标头。",
    "删除所有包含文件中 <?php 之前的任何空白或 BOM，并确保在任何 echo 或 HTML 之前调用 session_start()：\n<?php\nsession_start();\n// 其余代码\n?>"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.php.net/manual/en/function.session-start.php",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-04-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}