When you want to browse an URL from your browser you type an URL. The browser puts the url inside an HTTP REQUEST like this:
GET /path/to/resource.php?var=data1&othervar=data2 HTTP/1.1
Host: example.com
Connection: keep-alive
"empty line"
Then a webserver gives you an answer like this:
HTTP/1.0 200 OK
Date: Fri, 02 Sep 2011 14:37:36 GMT
Server: Apache
Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 149
Content-Type: text/javascript; charset=utf-8
Connection: keep-alive
"empty line"
"149 bytes of Response data"
Every line like this "Header-Name: header_value
" is an header.
PHP header function adds an header to the response before sending it to user's browser.
In your example the header is:
Location: http://google.com
And it's added just after the last header before the "empty line" (which is a line which contains only a
).
POST requests are different from GET requests because you have a request body after the "empty line"):
POST /path/to/resource.php HTTP/1.1
Host: example.com
Connection: keep-alive
Content-Length: "number of bytes in the body"
"empty line"
variable=data&othervar=data2
In conclusion an HTTP request is made like this:
- Request/response row (POST or GET followed by url and http version for request, Http version followed by response code and response string for the response) ended with
- Request/response headers (header-name: header_value
)
- empty row (
)
- Response/request body
PS. Rows are ALWAYS closed by "
" bytes ("empty lines" are made of just those two bytes).