PHP headers_sent() 函数

定义和用法

headers_sent() 函数检查 HTTP 标头是否已被发送以及在哪里被发送。

如果报头已发送,则返回 true,否则返回 false。

语法

headers_sent(file,line)
参数 描述
file,line

可选。

如果设置 file and line 参数,headers_sent() 会把输出开始的 PHP 源文件名和行号存入 file 和 line 变量中。

సలహా మరియు ప్రకటనలు

ప్రకటనలు:Once the header block has been sent, it cannot be used header() ఫంక్షన్ ఇతర హెడర్లను పంపడానికి ఉపయోగించండి. ఈ ఫంక్షన్ ఉపయోగించడం ద్వారా కనీసం HTTP హెడర్లకు సంబంధించిన తప్పు సందేశాలను నివారించవచ్చు.

ప్రకటనలు:optional file and line పరిమాణం ఉన్నది PHP 4.3 లో జోడించబడింది.

ప్రతిమాత్రము

ఉదాహరణ 1

<?php
// If headers have not been sent, send one
if (!headers_sent())
  {
  header("Location: http://www.codew3c.com/");
  exit;
  }
?>
<html>
<body>
...
...

ఉదాహరణ 2

Use optional file and line parameters:

<?php
// Pass $file and $line for future use
// Do not pre-assign them
if (!headers_sent($file, $line))
  {
  header("Location: http://www.codew3c.com/");
  exit;
  // Trigger an error here
  }
else
  {
  echo "Headers sent in $file on line $line";
  exit;
  }
?>
<html>
<body>
...
...