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:

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: 2015.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.0

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Configuring and Sending out Emails

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

Controlling HTTP Response Header Lines in PHP Scripts

 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

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Outdated Tutorials

 References

 PDF Printing Version