PHP 教程 PHP 表单 PHP 高级教程 PHP 数据库 PHP XML PHP 与 AJAX PHP 参考手册

发布于 2016-11-18 14:34:08 | 96 次阅读 | 评论: 0 | 来源: 网络整理


定义和用法

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.phperz.com/");
 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.phperz.com/");
 exit;
 // Trigger an error here
 }
 else
 {
 echo "Headers sent in $file on line $line";
 exit;
 }
 ?>

 <html>
 <body>

 ...
 ... 

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务