The caching of the Web page is controlled by the "Cache-control" in the HTTP message header, the common value has private, No-cache, Max-age, must-revalidate, etc., the default is private. Its role is divided into the following situations according to different ways of re browsing:
(1) Open a new window
Value is 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 is not again accessed within the time of this value, for example:
Cache-control:max-age=5 (for 5 seconds after accessing this page will not go to the server)
(2) Enter in the Address bar
A value of private or must-revalidate accesses the server only for the first visit and is no longer accessible.
Value is No-cache, then it is accessed every time.
Value is Max-age, the access is not repeated until it expires.
(3) Press the Back button
Value is private, must-revalidate, and Max-age, it will not be accessed again.
Value is No-cache, the access is repeated each time
(4) Press the Refresh button
Regardless of the value, repeated access
When the Cache-control value is "No-cache", accessing this page does not leave a page backup on the Internet temporary article folder.
In addition, caching can also be affected by specifying a "Expires" value. For example, to specify that the Expires value is a long past time, if you repeatedly press ENTER in the Address bar when you visit the network, you will repeat the visit each time: Expires:fri, Dec 1999 16:00:00 GMT
For example: Prevent the page from being cached in IE
HTTP Response message header settings:
CacheControl = No-cache
Pragma=no-cache
Expires =-1
Expires is a good thing, if the Web page on the server often changes, set it to-1, indicating immediate expiration. If a page is updated daily 1 o'clock in the morning, you can set the expires to 1 o'clock in the morning the next day.
When the HTTP1.1 server specifies CacheControl = No-cache, the browser does not cache the Web page.
Legacy HTTP 1.0 Servers cannot use Cache-control headers.
So for backward compatibility with HTTP 1.0 servers, IE uses the Pragma:no-cache header to provide special support for HTTP.
If the client communicates through a secure connection (https://)/with the server, and the server returns Pragma:no-cache headers in the response,
Then Internet Explorer does not cache this response. Note: Pragma:no-cache only prevents caching when used in a secure connection, and if used in an unsecured page, the processing is the same as expires:-1, and the page is cached but marked as immediately expired.
Header Common Instructions
The header is divided into three parts:
The first part is the HTTP protocol version (http-version);
The second part is state code (status);
The third part is the causal phrase (reason-phrase).
Copy Code code as follows:
Fix 404 Pages: Use this header directive to resolve the 404 header generated by the URL rewrite
Header (' http/1.1 OK ');
Set 404 Header: Page not found
Header (' http/1.1 404 Not Found ');
Page permanent redirect to tell the search engine to update their URLs
Set moved Permanently header (Good for redrictions)
Use with location header
Header (' http/1.1 moved Permanently ');
Access restricted
Header (' http/1.1 403 Forbidden ');
Server error
Header (' http/1.1 Internal Server Error ');
Redirect to a new location
Redirect to a new location:
Header (' location:http://www.www.jb51.net);
Redirect after a period of delay
Redrict with delay:
Header (' refresh:10; Url=http://www.jb51.net ');
print ' You'll be redirected in 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 = 中文版)
Content language (en = 中文版)
Header (' content-language:en ');
Last modification time (available at cache time)
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 what to get is not yet updated
Header for telling the browser the content
did not get changed
Header (' http/1.1 304 not Modified ');
Set the length of the content (available when caching):
Set content Length (good for caching):
Header (' content-length:1234 ');
Used to download files:
Headers for a download:
Header (' Content-type:application/octet-stream ');
Header (' content-disposition:attachment; filename= "Example.zip");
Header (' content-transfer-encoding:binary ');
Prohibit caching of the current document:
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, June 1997 05:00:00 GMT ');
To 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 ');
Plain text file
Header (' Content-type:text/plain ');
JPG picture
Header (' Content-type:image/jpeg ');
ZIP file
Header (' Content-type:application/zip ');
PDF file
Header (' content-type:application/pdf ');
Audio MPEG (MP3,...) file
Header (' Content-type:audio/mpeg ');
Flash animation//show Sign In box
Header (' Content-type:application/x-shockwave-flash ');
Displays the logon dialog box, which can be used for HTTP authentication
Header (' http/1.1 401 Unauthorized ');
Header (' Www-authenticate:basic realm= "top Secret");
print ' Text that'll be displayed if the user hits cancel or ';
print ' enters wrong login data ';