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

What Is an HTTP Response?

This section describes what is an HTTP response - The message returned from a Web server to the client machine in response to an HTTP request from that client machine.

What Is an HTTP Response? A HTTP response is the message a Web server needs to return back to a Web client machine in response to an HTTP request from the same client machine. Based on the HTTP/1.1 protocol, after receiving and interpreting an HTTP request from a client machine, a Web server must responds with an HTTP response message with the following structure:

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 sample HTTP response with two header lines:

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

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

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
What Is an HTTP Response?