d.grassi84
d.grassi84

Reputation: 393

Sending custom non-standard HTTP status code with PHP

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

Answers (1)

d.grassi84
d.grassi84

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

Related Questions