Use of header functions

Source: Internet
Author: User
Tags functions header
Headers (header) is a string sent by the server before the HTTP coprocessor to the browser, in the header
There is still an empty line separating from the HTML file. For more information about HTTP, you can participate in RFC 2068 official documents
(http://www.w3.org/Protocols/rfc2068/rfc2068). Before sending back HTML data in PHP, you need to first
All headers are passed through.

Note: The traditional header must contain one of the following three kinds of headers and can only appear once.

Content-type:xxxx/yyyy
Location:xxxx:yyyy/zzzz
status:nnn xxxxxx

The new multi-header specification (Multipart MIME) can appear more than two times.

Usage examples

Example one: This example redirects the browser to the official website of PHP.
Header ("Location:http://www.php.net");
Exit
"?"

Example two: You can use the following headers when you want the user to get the latest information, not the Proxy or cache data.
Header ("Expires:mon, June June 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 three: Let the user's browser appear to be unable to find the file information.
Header ("status:404 not Found");
"?"

Example four: Allow users to download files.

Header ("Content-type:application/x-gzip");
Header ("content-disposition:attachment; filename= filename ");
Header ("Content-description:php3 generated Data");
"?"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.