Application of PHPheader function

Source: Internet
Author: User
Tags http authentication
The use of the PHPheader function's webpage Cache is controlled by the "Cache-control" in the HTTP message header, common values include private, no-cache, max-age, and must-revalidate. the default value is private. The function is divided into PHP header functions based on different browser methods.

The Cache of web pages is controlled by "cache-control" in the HTTP message header. common values include private, no-Cache, max-age, and must-revalidate, the default value is private. The function of browser review is divided into the following situations:
(1) open a new window ?? ? If the values are private, no-cache, and must-revalidate, the server will be accessed again when a new window is opened. If the max-age value is specified, the server will not be accessed again during this period, for example: Cache-control: max-age = 5 (indicating that the server will not be accessed again within 5 seconds after the webpage is accessed)
(2) in the address bar, press enter ?? ? If the value is private or must-revalidate, the server will be accessed only when the first access is made and will not be accessed later .?? ? If the value is no-cache, it will be accessed every time .?? ? If the value is max-age, the access will not be repeated before expiration.
(3) press the back button ?? If the values are private, must-revalidate, and max-age, no re-access will be performed ,?? If the value is no-cache, access is repeated each time.
(4) refresh and press the button.
When the Cache-control value is "no-cache", accessing this page does not leave page backup in the temporary article folder on the Internet.
In addition, specifying the "Expires" value also affects the cache. For example, if you specify the Expires value as a time that has passed, if you repeatedly press enter in the address bar when accessing this network, the access will be repeated at: Expires: Fri, 31 Dec 1999 16:00:00 GMT
For example, disable page caching in IE.
Http response message header settings:
CacheControl = no-cachePragma = no-cacheExpires =-1
Expires is a good stuff. if the webpage on the server changes frequently, set it to-1, indicating that it will expire immediately. If a webpage is updated at every day, you can set Expires to the next day.
When CacheControl = no-cache is specified on the HTTP1.1 server, the browser does not cache the webpage.
The Cache-Control title cannot be used for legacy HTTP 1.0 servers. To be backward compatible with HTTP 1.0 servers, IE uses the Pragma: no-cache title to provide special support for HTTP. If the client communicates with the server through a secure connection (https: //) and the server returns the Pragma: no-cache title in the response, Internet Explorer does not cache the response. Note: Pragma: no-cache prevents caching only when used in secure connections. if used on a non-secure page, the processing method is the same as Expires:-1, this page will be cached, but the headers marked as frequently-used instructions that expire immediately are divided into three parts: the first part is the HTTP protocol Version (HTTP-Version), and the second part is the Status code (Status ); the third part is the Reason Phrase (Reason-Phrase ).
// Fix 404 pages :? Use this header command to solve the 404 header generated by URL rewriting? Header ('http/1.1 200 OK ');???? // Set 404 header :? The page does Not find the header ('http/1.1 404 Not Found ');???? // The page is Permanently deleted. can I tell the search engine to update their urls // set Moved Permanently header (good for redrictions )?? // Use with location header ?? Header ('http/1.1 301 Moved Permanently ');?
// Access restricted header ('http/1.1 403 Forbidden ');
// Server Error header ('http/1.1 500 Internal Server Error ');?? // Redirect to a new location :?? Header ('Location: http://www.sina.com.cn );???? Redirection after a delay of some time // redrict with delay :?? Header ('refresh: 10; url = http://www.sina.com.cn ');?? Print 'You will be redirected in 10 seconds ';???? // Overwrite X-Powered-By value // override X-Powered-By: PHP :?? Header ('x-Powered-By: PHP/4.4.0 ');?? Header ('x-Powered-By: Brain/0.6b ');???? // Content language (en = English )?? Header ('content-language: en ');???? // The last modification time (which can be used when caching) // last modified (good for caching )?? $ Time = time ()-60; // or filemtime ($ fn), etc ?? Header ('last-Modified: '. gmdate ('d, d m y h: I: S', $ time). 'gmt ');???? // Tell the browser that the content to be retrieved has not been updated // header for telling the browser that the content ?? // Did not get changed ?? Header ('http/1.1 304 Not modified ');???? // Set the content length (which can be used for caching): // set content length (good for caching ):?? Header ('content-Length: 1234 ');???? // Used to download the object: // Headers for an download :?? Header ('content-Type: application/octet-stream ');?? Header ('content-Disposition: attachment; filename = "example.zip "');?? Header ('content-Transfer-Encoding: binary ');???? // Disable caching the current file: // load the file to send: readfile('example.zip ');?? // Disable caching of the current document :?? Header ('cache-Control: no-Cache, no-store, max-age = 0, must-revalidate ');?? Header ('expires: Mon, 26 Jul 1997 05:00:00 GMT ');??
// Set the content type: // Date in the pastheader ('pragma: no-cache ');?? // Set content type :?? Header ('content-Type: text/html; charset = ISO-8859-1 ');?? Header ('content-Type: text/html; charset = utf-8 ');?? Header ('content-Type: text/plain ');???? // Plain text file ?? Header ('content-Type: image/jpeg ');? ??? // JPG picture ?? Header ('content-Type: application/zip ');? ??? // ZIP file ?? Header ('content-Type: application/pdf ');? ??? // PDF file ?? Header ('content-Type: audio/mpeg ');? ??? // Audio MPEG (MP3,...) file ?? Header ('content-Type: application/x-shockwave-Flash ');? ??? // The logon dialog box is displayed, which can be used for HTTP authentication // Flash animation // show sign in box ?? Header ('http/1.1 401 unauthorized ');?? Header ('www-Authenticate: Basic realm = "Top Secret "');?? Print 'text that will be displayed if the user hits cancel or ';?? Print 'enters wrong login 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.