Home  >  Article  >  Backend Development  >  How to disable client caching in php

How to disable client caching in php

藏色散人
藏色散人Original
2021-06-21 09:21:251935browse

How to disable client-side caching in PHP: 1. For static pages, use the meta tag to set the expiration time of the web page and set the browser not to cache the page; 2. For PHP pages, use header('Pragma: no-cache'); to disable client caching.

How to disable client caching in php

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to disable client caching in php?

Generally we want to view a web page on the Internet, so when you visit this web page for the first time, the system first downloads the web page to a temporary folder on your local computer for caching. , when you visit this webpage for the second or third time within a certain period of time, the browser will directly read this file from the temporary folder of your local computer and display it. The advantage of this is to avoid It has to be downloaded again every time, which takes up a lot of time and network resources. It has to be said that the cache of the page speeds up the display of the web page. Of course, it also has its disadvantages. For example, when the web page on the server has been updated, but the locally displayed one is still not updated. Web pages, so that updated content cannot be displayed in a timely manner. In some cases, we need to disable browser caching so that the pages we see every time are the latest pages (such as background operations, real-time news on large websites page), then we need to disable browser caching. The following describes how to disable web page caching in four different page environments:

1. For static pages (set through meta tags):

  a679fab4093f1be3f1e7be26685068fa

<meta http-equiv="expires" content="Sunday 26 October 2008 01:00 GMT" />

or through pragma no -cache to set, pragma appears in the http-equiv attribute, use the no-cache value of the content attribute to indicate whether to cache the web page (in order to improve the speed, some browsers will cache the pages browsed by the viewer, through the following definition, the browser generally The page will not be cached, and the browser cannot be viewed offline).

<meta http-equiv="pragma" content="no-cache" />

2. For PHP pages:

   <?php  
   header(&#39;Cache-Control:no-cache,must-revalidate&#39;);    
   header(&#39;Pragma:no-cache&#39;);    
   ?>

Emphasis: For dynamic pages, the cached code must be placed before any HTML tag output, otherwise an error will occur.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to disable client caching in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn