Hudzilla.org - the homepage of Paul Hudson
Contents > Networks Wish List | Report Bug | About Me ]

15.4     HTTP

This is NOT the latest copy of this book; click here for the latest version.

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:

200

Request accepted; response attached

201

Request accepted; new object created on server

206

Request accepted; partial content attached

301

Content moved permanently

400

Bad request; client sent something bad

401

Unauthorised; client sent credentials, but they were rejected

403

Forbidden; server understood the request, but refuses to comply

404

Not found; URL requesting non-existent object was sent

500

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.





<< 15.3 Host and IP resolution: gethostbyaddr(), gethostbyname(), and gethostbynamel()   15.4.1 Sending custom headers: header() and headers_sent() >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is nine plus one?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow