Bug #81451 [Com]: http_response_code() does not override the status code generated by header()
| From: | afshin dot meh at gmail dot com | Date: | Fri, 10 Jun 2022 09:27:56 +0000 |
| Subject: | Bug #81451 [Com]: http_response_code() does not override the status code generated by header() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-241704@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81451&edit=1
ID: 81451
Comment by: afshin dot meh at gmail dot com
Reported by: karpulix at ya dot ru
Summary: http_response_code() does not override the status
code generated by header()
Status: Verified
Type: Bug
Package: *Network Functions
Operating System: Any
PHP Version: 8.0.10
Block user comment: N
Private report: N
New Comment:
I'm interested to work on this issue if it's not already in progress.
Previous Comments:
------------------------------------------------------------------------
[2021-09-17 15:21:52] cmb@php.net
Thank you for reporting this issue, and also for linking to the SO
question. Pete's answer[1] is very useful, and spot on.
It seems to me the proper solution would be for http_response_code()
to call sapi_header_op(SAPI_HEADER_SET_STATUS, â¦) instead of manually
setting SG(sapi_headers).http_response_code.
[1] <https://stackoverflow.com/questions/69197771/why-is-function-http-response-code-acting-strange-that-was-called-after-functi#answer-69213593>
------------------------------------------------------------------------
[2021-09-17 03:12:30] karpulix at ya dot ru
Description:
------------
http_response_code cannot override the status code generated by header
It doesn't work with php-server, nginx-server.
If it is not fixable, I guess it must be in the official documentation here https://www.php.net/manual/ru/function.http-response-code.php
and the function must be recognized as deprecated.
There is my question on Stackoverflow: https://stackoverflow.com/questions/69197771/why-is-function-http-response-code-acting-strange-that-was-called-after-functi
Test script:
---------------
<?php
header('HTTP/1.1 404 Not Found');
http_response_code(501);
http_response_code(502);
http_response_code(503);
Expected result:
----------------
HTTP/1.1 503 Service Unavailable
Host: localhost:9958
Date: Wed, 15 Sep 2021 17:20:05 GMT
Connection: close
X-Powered-By: PHP/8.0.10
Content-type: text/html; charset=UTF-8
Actual result:
--------------
HTTP/1.1 404 Not Found
Host: localhost:9958
Date: Wed, 15 Sep 2021 17:20:05 GMT
Connection: close
X-Powered-By: PHP/8.0.10
Content-type: text/html; charset=UTF-8
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81451&edit=1