CKTIS / PHP
headers_sent()
Verifica se o PHP já enviou os cabeçalhos.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
headers_sent(string &$filename = null, int &$line = null): boolVerifica se o PHP já enviou os cabeçalhos. Os parâmetros opcionais por referência identificam o ficheiro e a linha de início da saída. O texto ainda em buffer pode deixar os cabeçalhos por enviar. Depois de enviar saída sem buffer é tarde para os alterar.
Assinatura
headers_sent(string &$filename = null, int &$line = null): bool
Saída do exemplo
sent
[false,false,true,true]
Exemplos
<?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]);
Resultado
sent [false,false,true,true]