Brief analysis of HTTP header page cache control and header common instructions

  • 2020-06-23 00:05:17
  • OfStack

The caching of web pages is controlled by "ES1en-ES2en" in the HTTP header. The common values are private, ES4en-ES5en, ES6en-ES7en, must-ES9en, etc., and the default is private. Its function can be divided into the following cases according to different re-browsing methods:
(1) Open a new window
With values of private, ES14en-ES15en, must-ES17en, the server will be re-accessed when a new window access is opened.
If the ES19en-ES20en value is specified, the server will not be re-accessed during the time within this value, for example:
Cache-control: ES24en-ES25en =5(means that the server will not be visited again within 5 seconds after visiting this page)
(2) Enter in the address bar
A value of private or ES29en-ES30en will access the server only on the first visit and will not be accessed again.
A value of ES32en-ES33en is accessed every time.
A value of ES35en-ES36en will not be repeated until it expires.
(3) Press back and press twist
If the value is private, ES40en-ES41en, ES42en-ES43en, it will not be revisited.
A value of ES45en-ES46en is accessed repeatedly each time
(4) Press refresh and press twist
Whatever the value is, it will be accessed repeatedly. Right
When the Cache-ES51en value is "ES52en-ES53en", visiting this page does not leave a copy of the page in the Internet temporary article folder.
Also, the cache is affected by specifying the "Expires" value. For example, if you specify the value of Expires to be 1 time long past, if you repeatedly press enter in the address bar to access the network, you will repeatedly access Expires: Fri, 31 Dec 1999 16:00:00 GMT
For example, disable caching of pages on IE
http Response message header Settings:
CacheControl = no-cache
Pragma=no-cache
Expires = -1
Expires is a good thing. If pages on your server change frequently, set it to -1 to indicate immediate expiration. If a web page is updated at 1 am every day, Expires can be set to 1 am on the second day.
When es76EN1.1 server specifies CacheControl = ES78en-ES79en, the browser does not cache the page.
Older HTTP 1.0 servers cannot use the Cache-ES83en title.
So for backward compatibility with HTTP 1.0 servers, IE provides special support for HTTP using the Pragma: ES88en-ES89en title.
If the client communicates with the server via a secure connection (https://)/ and the server returns the title Pragma: ES94en-ES95en in response,
Internet Explorer does not cache this response. Note: Pragma: ES100en-cache prevents caching only if used in a secure connection. If used in a non-secure page, the page will be cached but marked as immediately expired, in the same manner as Expires:-1.

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

// fix 404 pages:    With this header Instruction 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');

// Page redirects are permanent and you can tell 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 A new location 
// redirect to a new location:
header('Location: http://www.www.ofstack.com);

 delay 1 Redirect after some time 
// redrict with delay:
header('Refresh: 10; url=https://www.ofstack.com');
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 for caching purposes )
// 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 to fetch 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 when you cache ):
// 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');

//  Disables caching of current documents :
// 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');
// 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 login dialog box that can be used to proceed HTTP certification 
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';


Related articles: