função PHP headers_sent ()
Definição e Uso
headers_sent () função verifica se os cabeçalhos HTTP enviados / para onde enviar.
Se o cabeçalho foi enviada, a função retorna TRUE, caso contrário retorna FALSE.
gramática
headers_sent(file,line)
参数 | 描述 |
---|---|
file,line | 可选。如果设置 file 和 line 参数,headers_sent() 会把输出开始的 PHP 源文件名和行号存入 file 和 line 变量中。 |
Dicas e Notas
Nota: uma vez que o bloco do cabeçalho foi enviada, você não será capaz de enviar um outro cabeçalho usando a função header ().
Nota: Os parâmetros opcionais file e line é novo no PHP 4.3.
exemplo 1
<?php
// If no headers are sent, send one
if (!headers_sent())
{
header("Location: http://www.w3cschool.cc/");
exit;
}
?>
<html>
<body>
...
...
// If no headers are sent, send one
if (!headers_sent())
{
header("Location: http://www.w3cschool.cc/");
exit;
}
?>
<html>
<body>
...
...
exemplo 2
Usando os parâmetros opcionais file e line:
<?php
// $file and $line are passed in for later use
// Do not assign them values beforehand
if (!headers_sent($file, $line))
{
header("Location: http://www.w3cschool.cc/");
exit;
// Trigger an error here
}
else
{
echo "Headers sent in $file on line $line";
exit;
}
?>
<html>
<body>
...
...
// $file and $line are passed in for later use
// Do not assign them values beforehand
if (!headers_sent($file, $line))
{
header("Location: http://www.w3cschool.cc/");
exit;
// Trigger an error here
}
else
{
echo "Headers sent in $file on line $line";
exit;
}
?>
<html>
<body>
...
...
PHP Manual Completo HTTP Referência