Chapter 2: Beginning PHP 4

December 18, 2000

Brought to you by:




Table of contents:
The HTTP Request

The browser sends the HTTP request to the web server and it contains the following:

The Request Line

The first line of every HTTP request is the request line, which contains three pieces of information:

  • An HTTP command known as a method

  • The path from the server to the resource that the client is requesting

  • The version number of HTTP.
So, an example request line might look like this:

GET /testpage.htm HTTP/1.1

The method is used to tell the server how to handle the request. Here are three of the most common methods that might appear in this field:







There are a number of other methods supported by HTTP - including PUT, DELETE, TRACE, CONNECT, and OPTIONS. As a rule, you'll find that these are less common; they are therefore beyond the scope of this discussion.If you want to know more about these, take a look at RFC 2068, which you can find at http://www.rfc.net.

The HTTP Header

The next bit of information sent is the HTTP header. This contains details of what document types the client will accept back from the server, like the type of browser that has requested the page, the date, and general configuration information. The HTTP request's header contains information that falls into three different categories:

  • General: contains information about either the client or server, but not specific to one or the other

  • Entity: contains information about the data being sent between the client and server

  • Request: contains information about the client configuration and different types of acceptable documents

An example HTTP header might look like this:

Accept: */*
Accept-Language: en-us
Connection: Keep-Alive
Host: www.wrox.com
Referer: http://webdev.wrox.co.uk/books/SampleList.php?bookcode=3730
User-Agent: Mozilla (X11; I; Linux 2.0.32 i586)

As you can see, the HTTP header is composed of a number of lines; each line contains the description of a piece of HTTP header information, and its value.

There are many different lines that can comprise a HTTP header, and most of them are optional, so HTTP has to indicate when it has finished transmitting the header information. To do this, a blank line is used. In HTTP 1.1, a request must comprise of at least a request line and a HOST header.

The HTTP Body

If the POST method was used in the HTTP request line, then the HTTP request body will contain any data that is being sent to the server - for example, data that the user typed into an HTML form (we'll see examples of this later in the book). Otherwise, the HTTP request body will be empty.

The HTTP Response

The HTTP response is sent by the server back to the client browser, and contains the following.

The Response Line

The response line contains only two bits of information:

  • The HTTP version number

  • An HTTP request code that reports the success or failure of the request

An example response line might look like this:

HTTP/1.1 200 OK

This example returns the HTTP status code 200, which represents the message "OK". This denotes the success of the request, and that the response contains the required page or data from the server. You may recall that we mentioned the status code 404 a few pages ago - if the response line contains a 404 then the web server failed to find the requested resource. Error code values are three-digit numbers, where the first digit indicates the class of the response. There are five classes of response:


The HTTP Header

The HTTP response header is similar to the request header, which we discussed above. In the HTTP response, the header information again falls into three types:

  • General: contains information about either the client or server, but not specific to one or the other

  • Entity: contains information about the data being sent between the client and the server

  • Response: contains information about the server sending the response and how it can deal with the response

Once again, the header consists of a number of lines, and uses a blank line to indicate that the header information is complete. Here's a sample of what a header might look like, and the name of each line down the side:

HTTP/1.1 200 OK- the status line
Date: Mon, 1st Nov 1999, 16:12:23 GMT- the general header
Server: Apache/1.3.12 (Unix) (SUSE/Linux) PHP/4.0.2- the response header
Last-modified: Fri, 29th Oct 1999, 12:08:03 GMT- the entity header

The first line we've already discussed, the second is self-explanatory. On the third line, "Server", indicates the type of software the web server is running, and as we are requesting a file somewhere on the web server, the last bit of information refers to the last time the page we are requesting was modified.

The header can contain much more information than this, or different information, depending on what is requested. If you want to know more about the different types of information contained in the three parts of the header, you'll find them listed in RFC 2068 (Sections 4.5, 7.1 and 7.2).

The HTTP Body

If the request was successful, then the HTTP response body contains the HTML code (together with any script that is to be executed by the browser), ready for the browser's interpretation.




PAGE: 1 I 2 I 3 I 4 I FIRST PAGE
 

Research and Reports

Storage Virtualization Guide
May 2012

Network Computing: May 2012

TechWeb Careers