Trongate Docs
switch to dark modeswitch to dark mode
Understanding HTTP Response Status Codes

Understanding HTTP Response Status Codes

What Are HTTP Response Status Codes?

Hypertext Transfer Protocol (HTTP) response status codes  are numeric values that get issued by servers in response to requests that have been sent to the server. Most developers will be familiar with the phrase '404 Error'.  The '404' in this instance refers to the HTTP response status code that usually gets issued by a server whenever a page is not found.  Other well known response codes included '200' which is the status of a webpage (or endpoint) that has successfully loaded, and also '301' which indicates when a webpage has moved permanently.  These are just a few of the HTTP Response Status Codes that are available.  There are, however, lots of HTTP Response Status Codes - with more are being added all the time!

How To Fetch HTTP Response Status Codes In PHP

In PHP, you can fetch the HTTP Response Status Code by using PHP's inbuilt http_response_code() function.  For example,

$status = http_response_code();
echo $status; //outputs (something like) 200

How To Set HTTP Response Status Codes In PHP

In PHP, you set the HTTP Response Status Code (for a webpage or an API endpoint) by invoking http_response_code() and passing in a numeric value - that represents the HTTP Response Status Code - into the method.  For example,


Just To Let You Know
In instances where you display content on your server and you do not actively declare an HTTP Response Status Code then the status value of 200 will be issued automatically.

HTTP Response Status Codes Reference

Code Description
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
305 Use Proxy
307 Temporary Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
422 Unprocessable Entity
417 Expectation Failed
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported


If you have a question or a comment relating to anything you've see here, please goto the Help Bar.