PHP Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 3.00

Response Header Lines of Static Files

This section provides a tutorial example on how to test and view HTTP response header lines returned by IIS on 3 types of static files: HTML document, GIF image file, and PDF document.

Since I am using IIS (Internet Information Service) as the Web server, static files will be served directly by IIS server. It will set the status line and header lines for you based on the information collected from the static file the HTTP request is asking. For example, the "Content-Type" header line will be set based on the file name extension and the MIME settings of the server configuration. The "Content-Length" header line will be set to the size of the file.

Let's look at 3 examples of different types of static files. All of them are stored on my local machine at c:\inetpub\wwwroot, where the IIS is serving documents from.

1. Command: "php HttpRequestGet.php /hello.html" gives us:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Sun, 13 Nov 2005 04:34:17 GMT
Content-Type: text/html
Accept-Ranges: bytes
Last-Modified: Sun, 13 Nov 2005 04:31:16 GMT
ETag: "608fa7aaf8ebc51:c61"
Content-Length: 38

<html><body>Hello world!</body></html>

Couple of interesting notes here:

  • Content-Type was set to "text/html", because the file name extension was "html".
  • The request was marked as HTTP/1.0 in HttpRequestGet, but IIS responded with a higher version, HTTP/1.1.
  • I also tried to use HTTP/1.1 in my request, but IIS returned with an error. Why IIS could not support HTTP/1.1 request?
  • Notice that there was a blank line to separate the header lines and the entity body as required by the HTTP specification.

2. Command: "php HttpRequestGet.php /dot.gif" gives us:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Sun, 13 Nov 2005 04:40:17 GMT
Content-Type: image/gif
Accept-Ranges: bytes
Last-Modified: Sun, 11 Aug 2002 20:48:20 GMT
ETag: "04237ecd343c21:c61"
Content-Length: 43

GIF89a......

As you can see, Content-Type was set correctly to "image/gif" for file name extension "gif", as defined in the MIME settings. I could not include the entire entity body here because it contains binary data.

3. Command: "php HttpRequestGet.php /hello.pdf" gives us:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Sun, 13 Nov 2005 04:45:03 GMT
Content-Type: application/pdf
Accept-Ranges: bytes
Last-Modified: Sun, 27 Jul 2003 20:22:12 GMT
ETag: "0b2f4c27c54c31:c61"
Content-Length: 909

%PDF-1.3
% ...
4 0 obj
......

Again, Content-Type was set correctly to "application/pdf" for file name extension "pdf", as defined in the MIME settings. I truncated the entity body to save some space.

Last update: 2005.

Sections in This Chapter

What Is an HTTP Response?

HTTP Response Header Lines

header() - Inserting a Raw Header Lines

HttpRequestGet.php - Viewing Header Lines

Response Header Lines of Static Files

HttpHeaderLines.php - Examples of Inserting Header Lines

Location: - Forcing the Browser to Redirect to Another URL

Content-Type: - Generating Non-HTML Response Body

Content-Disposition: - Sending Files for Downloading

Dr. Herong Yang, updated in 2009
Response Header Lines of Static Files