PHP headers_sent() 函数

PHP 教程 · 2019-01-26 14:57:40

定义和用法

headers_sent() 函数检查 HTTP 报头是否发送/已发送到何处。

如果报头已发送,该函数返回 TRUE,否则返回 FALSE。

语法


headers_sent(file,line)


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

提示和注释

注释:一旦报头块已经发送,您就不能使用 header() 函数来发送其它的报头。

注释:可选的 file 和 line 参数是 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 参数:


<?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 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

图解设计模式

图解设计模式

结城浩 / 杨文轩 / 人民邮电出版社 / 2017-1-1 / CNY 79.00

原版连续畅销12年、重印25次! 194张图表 + Java示例代码 = 轻松理解GoF的23种设计模式 《程序员的数学》《数学女孩》作者结城浩又一力作 ◆图文并茂 194张图表(包括57张UML类图)穿插文中,帮助理解各设计模式 ◆通俗易懂 用浅显的语言逐一讲解23种设计模式,读完此书会发现GoF书不再晦涩难懂 ◆专业实用 编写了Java程序代码来......一起来看看 《图解设计模式》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具