función de PHP headers_sent ()
Definición y Uso
headers_sent () función comprueba si las cabeceras HTTP enviadas / dónde enviar.
Si la cabecera ha sido enviado, la función devuelve TRUE, de lo contrario devuelve FALSO.
gramática
headers_sent(file,line)
参数 | 描述 |
---|---|
file,line | 可选。如果设置 file 和 line 参数,headers_sent() 会把输出开始的 PHP 源文件名和行号存入 file 和 line 变量中。 |
Notas y sugerencias
Nota: una vez que el bloque de cabecera ha sido enviado, usted no será capaz de enviar otro remate de cabeza usando la función header ().
Nota: Los parámetros opcionales archivo y linea son nuevas en PHP 4.3.
Ejemplo 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>
...
...
Ejemplo 2
Utilizando los parámetros opcionales archivo y linea:
<?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 Completo manual de referencia de HTTP