|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43009 headers_sent() is PHP responsibility not Apache! do your job please
Submitted: 2007-10-17 17:41 UTC Modified: 2009-12-22 14:19 UTC
Avg. Score:2.3 ± 1.9
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: hamdi at rawasy dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.4.7 OS: Irrelevant
Private report: No CVE-ID: None
 [2007-10-17 17:41 UTC] hamdi at rawasy dot com
Referring to my previous report that holds ID 42992

Yes, PHP is not responsible about virtual() behavior.
But I think that it's holding the full responsibility against headers_sent() behavior and I'm asking to fix headers_sent() not virtual(), as it says that headers was already sent while it wasn't, you could send any headers after that and no problems happens (there is no buffer controllers). So, is it still apache problem?

Also the filename & line number returned by headers_sent() indicates that headers wasn't sent! and that is stupid behavior

You should return true from headers_sent() only when filename & line number are set, otherwise return false.

I repeat, this bug is PHP problem located at headers_sent() function! Not anything else.

I think that your job here is to fix those bugs not throwing blame at others. So, do your job please!

Reproduce code:
virtual("empty.php");	// An empty file
var_dump(headers_sent($file, $line), $file, $line);

Expected result:
string(0) ""

Actual result:
string(0) ""


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-19 21:08 UTC] codeslinger at compsalot dot com
I suspect your problem is not a bug at all, but is the result of not deciphering an error message that is somewhat mis-leading.

What the error message says is "headers have already been sent".  What you appears to be complaining about is that you have not in fact sent any headers.

What you probably don't realize is that any text at all which is seen to be part of the web page, is considered to create a situation of "headers already sent".

The issue is not actually that the headers have been sent, the issue is that the headers MUST proceed any and all text.

The usual cause of this situation is when the php tag is not the actual start of the document.  if there is even a single space character in front of the tag it will cause this problem.  Also any blank lines after the end of the closing php tag can cause this problem.  And be sure to check all of your include files.  Blank lines at the end of include files drive me totally nuts until I figured out what was going on.

Any character at all, including blank lines, which is outside of the php code brackets is considered to be part of the web page itself.

In order to use php to send headers, you CAN'T send any other character at all to the web page.

The work-around, for sloppy editing/coding is to turn on output buffering, see the manual.  With output buffering enabled, php holds anything being sent, and it is able to insert headers in front of already sent text.  But this is really the wrong solution, the right solution is to fix your code.

The requirement that headers MUST be sent first is defined by the HTTP protocol itself and can not be changed.
 [2007-12-19 21:18 UTC] codeslinger at compsalot dot com
apologies for the poor grammar, I should have proof-read more carefully before hitting submit.
 [2008-01-24 21:03 UTC] codeslinger at compsalot dot com
I just now got around to reading the docs on "virtual" which your example program is using.

This bug is totally bogus.  The docs make it very clear what the behavior of "virtual" is.  This behavior is by design.

My previous comments about probable causes of "headers already sent" are valid, they just don't apply to your program example.
 [2008-05-27 17:11 UTC] hamdisahloul at hotmail dot com
If you think this is a bugus issue, then at least the output should be something like this:

string(0) "/path/to/empty.php"


string(0) ""

but not the actual result:

string(0) ""

how could headers_sent() acts stupid so it says the headers already sent, but don't indicate the file & line???
 [2009-12-22 14:19 UTC]
The output is fine.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Jan 29 02:03:33 2022 UTC