Reputation: 393
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!
Upvotes: 3
Views: 1854
Reputation: 393
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.
Upvotes: 3