Overview
HTTP status codes communicate the result of a request. PHP applications should return status codes that match the outcome rather than relying on response text alone.
Common code groups
2xxindicates successful processing.3xxindicates redirection or further action.4xxindicates a client-side request problem.5xxindicates a server-side failure.
Frequently encountered codes
200 OK: request succeeded.201 Created: a resource was created.204 No Content: success with no response body.301 Moved Permanently: permanent redirection.302 Found: temporary redirection.400 Bad Request: invalid request.401 Unauthorized: authentication is required or invalid.403 Forbidden: request is understood but not allowed.404 Not Found: resource does not exist.422 Unprocessable Content: request content cannot be processed.429 Too Many Requests: rate limit reached.500 Internal Server Error: unexpected server failure.503 Service Unavailable: service temporarily unavailable.
PHP usage
Use http_response_code() to set a response status. For redirects, send an appropriate Location header and stop further output.
Official resource
MDN HTTP response status codes: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status