Hypertext Transport Protocol is a very basic protocol as we saw earlier - implementing a web server in 30 lines of code shows how easy it can be. However, there is actually a remarkable degree of complexity behind it allows for a lot of flexibility, much of which lies in the plethora of status codes it has available.

These status codes are all three digits, and can be broken down into the following groups:

  • 1xx: Informational - Request received, continuing process

  • 2xx: Success - The action was successfully received, understood, and accepted

  • 3xx: Redirection - Further action must be taken in order to complete the request

  • 4xx: Client Error - The request contains bad syntax or cannot be fulfilled

  • 5xx: Server Error - The server failed to fulfil an apparently valid request

As you can see, 400-level errors are client errors - the client did not send the right kind of request, requested a file that does not exist, etc. The most common error, 404, is a client error meaning, "Object not found" - the user typed in a URL that did not exist. Also in the 400 series is 401, "Unauthorized", where the user did not provide the correct credentials to view the content.

In order to be able to manipulate HTTP skilfully, you need a list of the most important HTTP status codes - and there they are:


Request accepted; response attached


Request accepted; new object created on server


Request accepted; partial content attached


Content moved permanently


Bad request; client sent something bad


Unauthorised; client sent credentials, but they were rejected


Forbidden; server understood the request, but refuses to comply


Not found; URL requesting non-existent object was sent


Internal server error; the server encountered something internally (not from the client) that prevented it from fulfilling the request. This usually means the server or a module such as PHP is configured incorrectly and/or crashing.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Sending custom headers >>

Previous chapter: Host and IP resolution

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.