How to set up php without caching: 1. Set it through the meta tag; 2. Use the statement "Response.CacheControl="no-cache"" to set up no caching; 3. Use the statement "header('Pragma :no-cache'); "to set the php page not to be cached.
How to force the browser not to cache in PHP
Generally we want to view a web page on the Internet, then when you When you visit this webpage for the first time, the system will first download this webpage to a temporary folder on your local computer for caching. When you visit this webpage for the second and third time within a certain period of time, At that time, the browser will directly read the file display from the temporary folder of your local computer. The advantage of this is to avoid re-downloading every time, which takes up a lot of time and network resources. It must be said that the caching of the page is accelerated. Of course, it also has its disadvantages if the web page is not displayed. For example, when the web page on the server has been updated, but the locally displayed web page is still an unupdated web page, the 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 pages of large websites). At this time, we have to disable browser caching. The following describes the four different Disable web page caching in the page environment:
1. For static pages (set through meta tags):
Or set through pragma no-cache, pragma appears in http-equiv In the 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 browser. Through the following definition, the browser generally will not cache the page, and the browser cannot be offline. browse).
2. For ASP pages:
<% Response.Buffer=true Response.CacheControl="no-cache" '禁止代理服务器缓存本页面 Response.Expires=-1000 '让页面立即过期(这儿最好设置一个绝对值较大的负数) %>
3. For JSP pages:
<% if(request.getProtocol().compareTo("HTTP/1.0")==0){ response.setHeader("Pragma","no-cache"); } if(request.getProtocol().compareTo("HTTP/1.1")==0){ response.setHeader("Cache-Control","no-cache"); } response.setDateHeader("Expires",0); %>
4. For PHP pages:
Emphasis: For For dynamic pages, the cached code must be placed before any HTML tag output, otherwise an error will occur.
For more related knowledge, please visitPHP Chinese website!
The above is the detailed content of How to set browser not to cache in php. For more information, please follow other related articles on the PHP Chinese website!