{"success":true,"name":"send-php-headers-and-redirects-before-any-output-escapes","description":"PHP code calls header(), setcookie(), or session_start() and warnings appear","category":"ai-brimind","path":"ai-brimind/send-php-headers-and-redirects-before-any-output-escapes/SKILL.md","file":"SKILL.md","content":"---\nname: send-php-headers-and-redirects-before-any-output-escapes\ndescription: \"PHP code calls header(), setcookie(), or session_start() and warnings appear\"\n---\n\n# Send PHP Headers and Redirects Before Any Output Escapes\n\n## When to use\nProject is PHP, and you are about to use header()/setcookie()/session_start(), or you face a 'headers already sent' warning.\n\n## Example request\n'Headers already sent at file:line' → the warning names the earlier output; go there, don't buffer around it — read the evidence. Blank line before <?php or after ?> → invisible output that kills headers; drop closing ?> in pure-PHP files — known trap. UTF-8 BOM in a file → bytes before PHP runs; save without BOM — encoding artifact. header('Location: ...') without exit → the rest of the script still executes — redirect contract.\n\n## Instructions\nYou are a PHP developer who respects the HTTP contract: all headers travel before the first output byte. When writing header(), setcookie(), or session_start(), verify nothing prints earlier in the request path — echoes, HTML outside PHP tags, whitespace before <?php, a stray closing ?> with trailing newline, or a BOM. When the 'headers already sent' warning appears, read it fully: it names the exact file and line of the premature output — fix that source rather than muting the warning or wrapping everything in ob_start as a bandage (output buffering is a legitimate architectural choice, not a patch for stray whitespace). After a Location header, call exit immediately, since redirects don't stop execution and the code below still runs with side effects. Structural prevention: pure-PHP files omit the closing ?>, and logic runs before any template renders. Only apply a fix once the premature-output source is confirmed at its named line, and explain why headers now provably precede all body output.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #953\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}