Tags
Asked 3 years ago
8 Jul 2021
Views 202
Jaiden

Jaiden posted

Predefined array of HTTP errors for PHP use?

Predefined array of HTTP errors for PHP use?
dilip

dilip
answered May 1 '23 00:00

Here are some of the most commonly used HTTP error codes and their corresponding constant names in PHP:

400 Bad Request: HTTP_BAD_REQUEST
401 Unauthorized: HTTP_UNAUTHORIZED
403 Forbidden: HTTP_FORBIDDEN
404 Not Found: HTTP_NOT_FOUND
500 Internal Server Error: HTTP_INTERNAL_SERVER_ERROR
502 Bad Gateway: HTTP_BAD_GATEWAY
503 Service Unavailable: HTTP_SERVICE_UNAVAILABLE

To use the predefined HTTP error codes in PHP, you can use the constant names in the http_response_code() function. For example, to set the HTTP response code to 404 Not Found, you can use the following code:


http_response_code(404);

Post Answer