Learn notes using Cache control :private

  • 2020-05-07 20:43:04
  • OfStack

According to different ways of re-browsing, its function can be divided into the following situations:
(1) open a new window
The values are private, no-cache, must-revalidate, and the server is revisited when a new window is opened.
If the max-age value is specified, the server will not be re-accessed during the time within this value, for example:
Cache-control: max-age =5

(2) press enter in the address bar
If the value is private or must-revalidate, the server will be accessed only on the first access and will not be accessed again.
The value is no-cache, which is accessed every time.
If the value is max-age, the access is not repeated until it expires.

(3) press backward and press twist
Values of private, must-revalidate, max-age are not revisited,
The value is no-cache, and the access is repeated each time

(4) press refresh and press twist
No matter what value it is, it will be accessed repeatedly. Right
When the Cache-control value is "no-cache", accessing this page does not leave a page backup in the Internet temporary article folder.
Also, the cache is affected by specifying the "Expires" value. For example, if you specify that the Expires value is a long past time, then if you repeatedly press enter in the address bar when accessing the network, it will be repeated every time: Expires: Fri, 31 Dec 1999 16:00:00 GMT
For example, pages are not 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 changes frequently, set it to -1 to indicate an immediate expiration. If a web page is updated at 1 am each day, you can set Expires to 1 am the next day.
When the HTTP1.1 server specifies CacheControl = no-cache, the browser will not cache the page.

The old HTTP 1.0 server cannot use Cache-Control titles.

So for backward compatibility with HTTP 1.0 servers, IE provides special support for HTTP using Pragma: no-cache titles.
If the client communicates with the server via a secure connection (https://)/ and the server returns the Pragma: no-cache title in the response,
Then Internet Explorer does not cache the response. Note: Pragma: no-cache prevents caching only when used in a secure connection. If used in a non-secure page, the page is handled the same way as Expires:-1, but is marked as immediately expired.

header common instructions
header is divided into three parts:
Part 1 is the version of the HTTP protocol (HTTP-Version);
Part 2 is the status code (Status);
Part 3 is the reason phrase (Reason-Phrase).


<?php
// fix 404 pages:    With this header Command to solve URL overwritten 404 header
header('HTTP/1.1 200 OK');  

// set 404 header:    Page not found 
header('HTTP/1.1 404 Not Found');  

//  Pages are permanently deleted, telling search engines to update them urls
// set Moved Permanently header (good for redrictions)  
// use with location header  
header('HTTP/1.1 301 Moved Permanently');  
//  Limited access 
header('HTTP/1.1 403 Forbidden');
//  Server error 
header('HTTP/1.1 500 Internal Server Error');

//  Redirected to 1 Three new locations 
// redirect to a new location:  
header('Location: //www.ofstack.com);  

 delay 1 Redirect after some time 
// redrict with delay:  
header('Refresh: 10; url=http://www.sina.com.cn');  
print 'You will be redirected in 10 seconds';  

//  cover  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 of the language  (en = English)
// content language (en = English)  
header('Content-language: en');  

// Last modified time  ( You can use it in the cache )
// 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');  

//  Tells the browser that the content being retrieved has not been updated 
// header for telling the browser that the content  
// did not get changed  
header('HTTP/1.1 304 Not Modified');  

//  Sets the length of the content  ( You can use it for caching ):
// set content length (good for caching):  
header('Content-Length: 1234');  

//  For downloading files :
// Headers for an download:  
header('Content-Type: application/octet-stream');  
header('Content-Disposition: attachment; filename="example.zip"');  
header('Content-Transfer-Encoding: binary');  

//  Caching of the current document is disabled :
// 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');    

//  Displays the login dialog box that can be used to perform HTTP certification 
// 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';
?>

Now for the form filling, we can use AJAX to verify the user at any time and give a friendly prompt. However, when the user fails to pay attention to the friendly prompt of AJAX, he submits the wrong form, jumps back to the original page, and all the information filled in is lost.
To support page bounce, there are the following ways:
1. Use session_cache_limiter method: session_cache_limiter('private, must-revalidate '); However, it is important to note that the session_cache_limiter() method is useful before the session_start() method;
2. Set the method of control cache with header: header(' Cache-control :private, must-revalidate ');


Related articles: