69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

PHP headers_sent() 函數(shù)

PHP headers_sent() 函數(shù)

PHP HTTP 參考手冊 完整的 PHP HTTP 參考手冊

定義和用法

headers_sent() 函數(shù)檢查 HTTP 報頭是否發(fā)送/已發(fā)送到何處。

如果報頭已發(fā)送,該函數(shù)返回 TRUE,否則返回 FALSE。

語法

headers_sent(file,line)

參數(shù) 描述
file,line 可選。如果設(shè)置 file 和 line 參數(shù),headers_sent() 會把輸出開始的 PHP 源文件名和行號存入 file 和 line 變量中。

提示和注釋

注釋:一旦報頭塊已經(jīng)發(fā)送,您就不能使用 header() 函數(shù)來發(fā)送其它的報頭。

注釋:可選的 file 和 line 參數(shù)是 PHP 4.3 中新增的。

實例 1

<?php
// If no headers are sent, send one
if (!headers_sent())
{
header("Location: http://www.w3cschool.cc/");
exit;
}
?>

<html>
<body>

...
...

實例 2

使用可選的 file 和 line 參數(shù):

<?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>

...
...

PHP HTTP 參考手冊 完整的 PHP HTTP 參考手冊
相關(guān)文章