downloads | documentation | faq | getting help | mailing lists | reporting bugs | sites | links | my 
search for in the  
Last updated: Mon, 16 Jul 2012


(PHP 3 >= 3.0.8, PHP 4, PHP 5)

headers_sent -- Checks if or where headers have been sent


bool headers_sent ( [string &file [, int &line]] )

headers_sent() will return FALSE if no HTTP headers have already been sent or TRUE otherwise. If the optional 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.

You can't add any more header lines using the header() function once the header block has already been sent. Using this function you can at least prevent getting HTTP header related error messages. Another option is to use Output Buffering.

注: The optional file and line parameters where added in PHP 4.3.0.

例子 1. Examples using headers_sent()


// If no headers are sent, send one
if (!headers_sent()) {
// An example using the optional file and line parameters, as of PHP 4.3.0
// Note that $filename and $linenum are passed in for later use.
// Do not assign them values beforehand.
if (!headers_sent($filename, $linenum)) {

// You would most likely trigger an error here.
} else {

"Headers already sent in $filename on line $linenum\n" .
"Cannot redirect, for now please click this <a " .
"href=\"\">link</a> instead\n";


See also ob_start(), trigger_error(), and header() for a more detailed discussion of the matters involved.

 Last updated: Mon, 16 Jul 2012
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at:
Last updated: Thu Jul 7 19:13:47 2005 CST