参数 | 描述 |
---|---|
file,line | 可选。如果设置 file 和 line 参数,headers_sent() 会把输出开始的 PHP 源文件名和行号存入 file 和 line 变量中。 |
注释:一旦报头块已经发送,就不能使用 header() 添加多个报头行。
注释:可选的 file 和 line 参数是 PHP 4.3 中新加的。
<?php
// 如果报头未发送,则发送一个
if (!headers_sent()
)
{
header("Location: http://www.w3school.com.cn/");
exit;
}
?>
<html>
<body>
...
...
使用可选的 file 和 line 参数:
<?php
// 传递 $file 和 $line,供日后使用
// 不要预先为它们赋值
if (!headers_sent($file, $line)
)
{
header("Location: http://www.w3school.com.cn/");
exit;
// Trigger an error here
}
else
{
echo "Headers sent in $file on line $line";
exit;
}
?>
<html>
<body>
...
...
制作:
http://www.7di.net 生活网搜集整理 参考: http://www.w3school.com.cn/php/func_http_headers_sent.asp |