Home >Backend Development >PHP Tutorial >Use of header function_PHP tutorial
The header is a string sent by the server before transmitting HTML data to the browser using the HTTP protocol. A blank line is required between the header
and the HTML file. For detailed instructions on HTTP, please refer to the RFC 2068 official document
(http://www.w3.org/Protocols/rfc2068/rfc2068). Before sending back HTML data in PHP, all headers must be
passed.
Note: Traditional headers must contain one of the following three headers and can only appear once.
Content-Type: xxxx/yyyy
Location: xxxx:yyyy/zzzz
Status: nnn xxxxxx
Can appear more than twice in the new multipart header specification (Multipart MIME).
Usage Example
Example 1: This example redirects the browser to the official website of PHP.
Header("Location: http://www.php.net");
exit;
>?
Example 2: To allow users to get the latest data every time, instead of For data in Proxy or cache, you can use the following header
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate(" D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
>?
Example 3: Let the user's browser display a message that the file cannot be found.
header("Status: 404 Not Found");
>?
Example 4: Allow users to download files.
header("Content-type: application/x-gzip");