当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > headers_sent() 函数

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 中的 headers_sent() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 444 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The headers_sent() function checks if / where the HTTP headers have been sent.
headers_sent()函数的作用是:检查标头是否已被发送以及在哪里被发送。

This function returns TRUE if headers has been sent or FALSE if not.
如果header被发送,那么该函数返回True;如果没有发送,则返回False。

Syntax
语法

headers_sent(file,line)

Parameter参数 Description描述
file,line 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 parameter]已经被设置,那么headers_sent()函数将把PHP源文件名和行数(这里的行数是指结果输出开始的那一行)输入文件以及行变量中。


Tips and Notes
注意点

Note: You can't add more header lines using header() once the header block has already been sent.
注意:当header块[header block]准备发送之前,你不可以使用header()一次性添加多个header。

Note:
The optional file and line parameters where added in PHP 4.3.
注意:这个“选择执行文件”[optional file]和行参数[line parameter]仅在PHP4.3以上版本中获得支持。


Example 1
案例1

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


Example 2
案例2

Using the optional file and line parameters:
使用可选文件和行参数的案例:

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

评论 (0) All

登陆 | 还没注册?