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

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 headers_sent() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 446 ::
收藏到网摘: 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

登陆 | 还没注册?