HTTP header is a simple string described in HTTP/1.1 specification.
If you have PHP header like:
<?php header("Location: www.example.com"); ?>
in Python that would be:
print "Location: www.example.com\n"
print """Location: /subfolder/ Content-type:text/html;charset=utf-8 Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT """
The header must be the first thing you send back to the client as response of their request.
(PHP 4, PHP 5)
header — Send a raw HTTP header
void header ( string $string [, bool $replace= true [, int $http_response_code ]] )
header() is used to send a raw HTTP header. See the » HTTP/1.1 specification for more information on HTTP headers.
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
No value is returned.
Example #1 Download dialog
If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the » Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.
Example #2 Caching directives
PHP scripts often generate dynamic content that must not be cached by the client browser or any proxy caches between the server and the client browser. Many proxies and clients can be forced to disable caching with: