I cannot find the right way to send a custom HTTP status code with PHP (for example: 454). I've tried using:
header('HTTP/1.1 454', true);
header('X-PHP-Response-Code: 454', true);
with no avail. Even if I get the X-PHP-Response-Code: 454
line in the response header, a HTTP/1.1 500 Internal Server Error
is always added at the top of it, overriding the status code.
I've tried http_response_code()
too.
Is there any way to send a custom non-standard HTTP status code with PHP?
Thanks!
The solution is to add the HTTP status description to the header. For example:
header('HTTP/1.1 454 My Custom Status', true);
PHP discards non-standard HTTP codes when provided without their description.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.