Home >Backend Development >PHP Tutorial >Use of header function_PHP tutorial

Use of header function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:27:21846browse

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");


header("Content-Disposition: attachment; filename=filename");
header("Content-Description: PHP3 Generated Data");
>?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531887.htmlTechArticleHeader is a string sent by the server before transmitting HTML data to the browser using HTTP protocol. A blank line is required between the header and the HTML file. Detailed instructions for HTTP can be found...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn