|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52555 Headers_List not returning HTTP Status Code
Submitted: 2010-08-06 12:50 UTC Modified: 2010-12-11 14:47 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Assigned: dragoonis (profile)
Status: Closed Package: *Web Server problem
PHP Version: 5.3.3 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
New email:
PHP Version: OS:


 [2010-08-06 12:50 UTC]
Ok so i've found the reason why this doesn't work but i'd like feedback on the appropriate area to change as this looks like it was intentionally developed this way.

headers_list() gets passed SG(sapi_headers).headers and prints them.
This works however when you do header() -> sapi_header_op() and you set a response code such as 'HTTP/1.0 404 Not Found'.
It does not put this header into SG(sapi_headers).headers but it puts it into SG(sapi_headers).http_response_code instead.

This looks to be intentional as there are special functions for updating the response code such as sapi_update_response_code()

So the end question is, should I modify sapi_header_op() to also include the response code in SG(sapi_headers).headers or should I modify headers_list() to receive SG(sapi_headers).headers and SG(sapi_headers).http_response_code.

I could also make a new function which only returns SG(sapi_headers).http_response_code but i think that's a waste of time and could update headers_list() or whatnot. 

FYI: I tested apache_response_headers() and got no http response code in their either.

Test script:

header("Content-type: text/plain");

header('HTTP/1.0 404 Not Found');

var_dump(headers_list()); exit;

Expected result:
array(3) {
    string(34) "X-Powered-By: PHP/5.3.2-1ubuntu4.2"
    string(30) "Content-type: text/plain"
    string(22) "HTTP/1.0 404 Not Found"

Actual result:
array(2) {
    string(34) "X-Powered-By: PHP/5.3.2-1ubuntu4.2"
    string(30) "Content-type: text/plain"


http_response_code (last revision 2010-08-08 22:49 UTC by
httpd_response_code (last revision 2010-08-08 22:48 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-06 12:54 UTC]
-Assigned To: +Assigned To: dragoonis
 [2010-08-06 13:42 UTC]
-Status: Assigned +Status: Bogus
 [2010-08-06 13:42 UTC]
RFC 2616 (Hypertext Transfer Protocol -- HTTP/1.1) makes a difference between the Status-Line (6.1) and the Headers (6.2) that we allow setting the Status-Line via header() is kind of a hack, headers_list() should only list headers so users can work with them easily (like splitting up at ": " etc.)
 [2010-08-06 14:15 UTC]
As per IRC conversations, the status_line or http_response_code are not headers therefore should not be returned from headers_list() so the conclusion is to make a new function to give you http_response_code. I will update this ticket with the patch.
 [2010-08-07 15:53 UTC]
The following patch has been added/updated:

Patch Name: http_response_code
Revision:   1281189200
 [2010-08-07 15:54 UTC]
After some discussions in IRC we have concluded that it's best to make a new function to give us the current response code rather than modifying existing functionality.

I've added the patch below to be tested and committed into TRUNK or wherever.

 [2010-08-07 16:18 UTC]
-Status: Bogus +Status: Assigned -Type: Bug +Type: Feature/Change Request
 [2010-08-09 00:48 UTC]
The following patch has been added/updated:

Patch Name: httpd_response_code
Revision:   1281307736
 [2010-08-09 00:49 UTC]
The following patch has been added/updated:

Patch Name: http_response_code
Revision:   1281307771
 [2010-08-09 15:10 UTC]
Automatic comment from SVN on behalf of kalle
Log: Implemented FR #52555 (Ability to get HTTP response code)
 - Patch by Paul Dragoonis
 [2010-08-09 15:11 UTC]
-Status: Assigned +Status: Closed
 [2010-08-09 15:11 UTC]
Committed to 5.3.99
 [2010-12-11 13:37 UTC] marc-bennewitz at arcor dot de

I can't find the function "http_response_code" within 5.3.4 and no documentation about it or a message on changelog of 5.3.4.

What does it mean "Committed to 5.3.99" ?
How many years we have to wait :/

It would be very helpful to have some publish time/version.

 [2010-12-11 14:47 UTC]
It is committed in trunk (svn trunk).
 [2010-12-11 14:58 UTC] marc-bennewitz at arcor dot de
Why it's not committed to a branch ?
When it will be available ?
 [2011-09-27 08:29 UTC] jorrit at ncode dot nl
It would be nice if the status code could also 
be set using this function. As mentioned in 
another comment, the current method of 
using header() is kind of a hack and the 
developer needs to provide the irrelevant 
HTTP version in order to set the response 
 [2011-09-27 08:56 UTC] dragoonis at gmail dot com
Hey jorrit at ncode dot nl,

If you see the following link, the current implementation of the function 
http_response_code is the following:

/* {{{ proto long http_response_code([int response_code])
    284    Sets a response code, or returns the current HTTP response code */

Hope this helps.
Paul Dragoonis.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC