Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

headers_sent()

Test whether PHP has already committed the response headers.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

headers_sent(string &$filename = null, int &$line = null): bool

Test whether PHP has already committed the response headers. The optional reference arguments identify the file and line where output began. Buffered output alone need not send headers. After unbuffered output commits them, a subsequent header change is too late.

Signature

headers_sent(string &$filename = null, int &$line = null): bool

Example output

sent
[false,false,true,true]

Examples

<?php
$before=headers_sent(); ob_start(); echo "preview"; $buffered=headers_sent(); ob_end_clean();
echo "sent\n"; $after=headers_sent($file,$line); echo json_encode([$before,$buffered,$after,$line>0]);

Result

sent
[false,false,true,true]

Sources