Skip to content

Instantly share code, notes, and snippets.

@dusnm
Created October 1, 2020 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dusnm/d0410fae368405d96b0c93db07a7a42e to your computer and use it in GitHub Desktop.
Save dusnm/d0410fae368405d96b0c93db07a7a42e to your computer and use it in GitHub Desktop.
PHP constants with descriptions of the most commonly used HTTP status codes
<?php
declare(strict_types=1);
/**
* Standard response for successful HTTP requests.
* The actual response will depend on the request method used.
* In a GET request, the response will contain an entity corresponding to the requested resource.
* In a POST request, the response will contain an entity describing or containing the result of the action.
*/
define('HTTP_STATUS_OK', 200);
/**
* The request has been fulfilled, resulting in the creation of a new resource.
*/
define('HTTP_STATUS_CREATED', 201);
/**
* The request has been accepted for processing, but the processing has not been completed.
* The request might or might not be eventually acted upon,
* and may be disallowed when processing occurs.
*/
define('HTTP_STATUS_ACCEPTED', 202);
/**
* The server successfully processed the request, and is not returning any content.
*/
define('HTTP_STATUS_NO_CONTENT', 204);
/**
* The server is delivering only part of the resource due to a range header sent by the client.
* The range header is used by HTTP clients to enable resuming of interrupted downloads,
* or split a download into multiple simultaneous streams.
*/
define('HTTP_STATUS_PARTIAL_CONTENT', 206);
/**
* This and all future requests should be directed to the given URI.
*/
define('HTTP_STATUS_MOVED_PERMANENTLY', 301);
/**
* The response to the request can be found under another URI using the GET method.
* When received in response to a POST (or PUT/DELETE),
* the client should presume that the server has received the data
* and should issue a new GET request to the given URI.
*/
define('HTTP_STATUS_SEE_OTHER', 303);
/**
* Indicates that the resource has not been modified
* since the version specified by the request headers If-Modified-Since or If-None-Match.
* In such case, there is no need to retransmit the resource
* since the client still has a previously-downloaded copy.
*/
define('HTTP_STATUS_NOT_MODIFIED', 304);
/**
* The server cannot or will not process the request due to an apparent client error.
*/
define('HTTP_STATUS_BAD_REQUEST', 400);
/**
* Specifically for use when authentication is required
* and has failed or has not yet been provided.
*/
define('HTTP_STATUS_UNAUTHORIZED', 401);
/**
* The request contained valid data and was understood by the server,
* but the server is refusing action.
* This may be due to the user not having the necessary permissions for a resource
* or needing an account of some sort,
* or attempting a prohibited action.
* The request should not be repeated.
*/
define('HTTP_STATUS_FORBIDDEN', 403);
/**
* The requested resource could not be found but may be available in the future.
* Subsequent requests by the client are permissible.
*/
define('HTTP_STATUS_NOT_FOUND', 404);
/**
* A request method is not supported for the requested resource;
* for example, a GET request on a form that requires data to be presented via POST,
* or a PUT request on a read-only resource.
*/
define('HTTP_STATUS_METHOD_NOT_ALLOWED', 405);
/**
* The requested resource is capable of generating only content
* not acceptable according to the Accept headers sent in the request.
*/
define('HTTP_STATUS_NOT_ACCEPTABLE', 406);
/**
* The server timed out waiting for the request.
* According to HTTP specifications: "The client did not produce a request
* within the time that the server was prepared to wait.
* The client may repeat the request without modifications at any later time.
*/
define('HTTP_STATUS_REQUEST_TIMEOUT', 408);
/**
* Indicates that the request could not be processed because of conflict in the current state of the resource.
*/
define('HTTP_STATUS_CONFLICT', 409);
/**
* The request is larger than the server is willing or able to process.
*/
define('HTTP_STATUS_PAYLOAD_TOO_LARGE', 413);
/**
* The request entity has a media type which the server or resource does not support.
*/
define('HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE', 415);
/**
* The client has asked for a portion of the file,
* but the server cannot supply that portion.
*/
define('HTTP_STATUS_RANGE_NOT_SATISFIABLE', 416);
/**
* The RFC specifies this code should be returned by teapots requested to brew coffee.
*/
define('HTTP_STATUS_I_M_A_TEAPOT', 418);
/**
* The request was well-formed but was unable to be followed due to semantic errors.
*/
define('HTTP_STATUS_UNPROCESSABLE_ENTITY', 422);
/**
* A generic error message, given when an unexpected condition was
* encountered and no more specific message is suitable.
*/
define('HTTP_STATUS_INTERNAL_SERVER_ERROR', 500);
/**
* The server either does not recognize the request method,
* or it lacks the ability to fulfil the request.
*/
define('HTTP_STATUS_NOT_IMPLEMENTED', 501);
/**
* The server was acting as a gateway or proxy and
* received an invalid response from the upstream server.
*/
define('HTTP_STATUS_BAD_GATEWAY', 502);
/**
* The server cannot handle the request.
*/
define('HTTP_STATUS_SERVICE_UNAVAILABLE', 503);
/**
* The server was acting as a gateway or proxy and
* did not receive a timely response from the upstream server.
*/
define('HTTP_STATUS_GATEWAY_TIMEOUT', 504);
/**
* The server does not support the HTTP protocol version used in the request.
*/
define('HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED', 505);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment