PHP Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.21

Controlling HTTP Response Header Lines

Part:   1  2  3  4  5  6  7 

PHP Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Non ASCII Characters with MySQL

Inputting Non ASCII Characters

Controlling Response Header Lines

HTTP Request Variables

Sessions

Using Cookies

PHP SOAP Extension

PHP SOAP Extension - Server

Directories, Files and Images

Using MySQL with PHP

... Table of Contents

This chapter describes:

  • HTTP Response Syntax
  • HTTP Response Header Lines
  • Controlling Header Lines
  • Viewing Header Lines
  • Header Lines of Static Files
  • Controlling Header Lines - Example Scripts
  • Forcing the Browser to Redirect
  • Generating Non-HTML Entity Body
  • Sending Files for Downloading

HTTP Response Syntax

Based on HTTP/1.1 protocol, after receiving and interpreting an HTTP request from a client, a server must responds with an HTTP response following the syntax below:

status-line
header-line
...
header-line

entity-body

Note that:

  • Response must have one status-line.
  • Response can have zero, one, or many header lines.
  • Response can only have zero or one entity-body.
  • There is a blank line between header lines and the entity body.
  • Status line, header line, and blank line must be ended with CRLF ("/r/n") characters.
  • Entity body is the actual data requested by the client request.
  • Header lines can be in any order.

Below is a simple HTTP response with two header lines:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 38

Hello world!

HTTP Response Header Lines

HTTP/1.1 response header lines allows the server to passes additional information about the response which cannot be placed in the status line. Header lines can be divided into three groups:

1. General header lines: Information about the transmission of the entire response message:

   Cache-Control      
   Connection         
   Date               
   Pragma             
   Trailer            
   Transfer-Encoding  
   Upgrade            
   Via                
   Warning          

(Continued on next part...)

Part:   1  2  3  4  5  6  7 

Dr. Herong Yang, updated in 2006
PHP Tutorials - Herong's Tutorial Notes - Controlling HTTP Response Header Lines