If you are using output buffering and you use the flush() command ANYWHERE headers_sent() will return true - even if the buffer is seemingly empty.
headers_sent说明bool headers_sent ( [string &file [, int &line]] )如果 HTTP 标头尚未被发送出去的话,headers_sent() 将返回 FALSE,否则返回 TRUE。如果指定了可选参数 file 和 line, headers_sent() 将会把 PHP 的文件名以及从哪一行开始有输出放到 file 和 line 变量中。 一旦标头已经被发送,将不能再使用 header() 函数来发送其它的标头。使用此函数至少可以避免避免与 HTTP 标头有关的错误信息。另一个选择是使用输出缓存。
相关问题的详细讨论参见 ob_start(),trigger_error() 和 header()。
add a note
User Contributed Notes
kamermans at teratechnologies dot net
22-Aug-2006 04:24
If you are using output buffering and you use the flush() command ANYWHERE headers_sent() will return true - even if the buffer is seemingly empty.
rajnesh at gmail dot com
25-Feb-2006 02:19
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.
Jakob B.
07-Jan-2006 07:03
<?php
trevize (shtrudel) gmail.com
30-Nov-2005 10:43
Note that in IIS (or at least the version that comes with W2K server), the server seems to do some buffering, so even if you output someting or cause a warning, the value of headers_sent() may be false because the headers haven't been sent yet.
php [at] barryhunter [.] co [.] uk
09-Sep-2005 06:42
In responce to: Terry 11-Feb-2005 03:58
alexrussell101 at gmail dot com
02-Sep-2005 06:31
To K.Tomono:
mark at dreamjunky dot com
29-Jun-2005 12:56
In case this comes up with anyone else, you might trigger headers to be sent if you have a PHP file with extra space after the closing ?>. In particular, if you include that file at the top of your main script, it will cause headers to send, followed by the space after the ?> in your included script. In short, make sure you don't have any space trailing your final ?>.
K.Tomono
22-Apr-2005 01:24
[code]
Terry
11-Feb-2005 11:58
For programmers used to Perl, note that sending a relative 'Location:' header sends a redirect to the browser in PHP, unlike Perl which will attempt to call relative URLs using an internal subrequest and return that page to the browser without redirecting. If you want to do the same trick in PHP, use include() or virtual().
php at fufachew dot REMOVEME dot com
29-Feb-2004 03:26
RE: antti at haapakangas dot net's post
antti at haapakangas dot net
29-Jan-2004 04:39
Re: php at fufachew dot com | ||