Php/func network headers sent
来自菜鸟教程
PHP headers_sent()函数
例
如果没有发送头,则发送一个:
<?php
if (!headers_sent()) {
header("Location: https://www.example.com/");
exit;
}
?>
<html>
<body>
...
...
定义和用法
headers_sent()函数检查是否/在何处发送了头文件。
句法
headers_sent(file,line)
参数值
| 参数 | 描述 |
|---|---|
| file | 可选的。如果设置了文件和行参数,则headers_sent()将在文件和行变量中开始输出的位置放置PHP源文件名和行号。 |
| line | 可选的。指定输出开始的行号 |
技术细节
| 返回值: | 如果已发送HTTP标头,则为TRUE,否则为FALSE |
| PHP版本: | 4.0+ |
| PHP更新日志: | PHP 4.3:添加了可选
file and line 参数 |
更多例子
例
使用可选的文件和行参数:
<?php
// $file and $line are passed in for later use
// Do not assign them values beforehand
if (!headers_sent($file, $line))
{
header("Location: https://www.example.com/");
exit;
// Trigger an error here
}
else
{
echo "Headers sent in $file on line $line";
exit;
}
?>
<html>
<body>
...
...