如果没有发送标头,则发送一个:
<?php
if (!headers_sent()) {
header("Location: https://www.91xjr.com/");
exit;
}
?>
<html>
<body>
...
...
headers_sent() 函数检查标头是否已发送/发送到何处。
headers_sent(
file,line)
Parameter | Description |
---|---|
file | Optional. If the file and line parameters are set, headers_sent() will put the PHP source file name and line number where output started in the file and line variables |
line | Optional. Specifies the line number where the output started |
返回值: | 如果已发送 HTTP 标头,则为 TRUE,否则为 FALSE |
---|---|
PHP 版本: | 4.0+ |
PHP 变更日志: | PHP 4.3:添加了可选的文件和线参数 |
使用可选的文件和行参数:
<?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.91xjr.com/");
exit;
// Trigger an error here
}
else
{
echo "Headers sent in $file on line $line";
exit;
}
?>
<html>
<body>
...
...
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!