How to set browser not to cache in php

藏色散人
Release: 2023-03-02 09:02:02
Original
4154 people have browsed it

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 set browser not to cache in php

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):

 
Copy after login

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).

Copy after login

2. For ASP pages:

<% Response.Buffer=true Response.CacheControl="no-cache" '禁止代理服务器缓存本页面 Response.Expires=-1000 '让页面立即过期(这儿最好设置一个绝对值较大的负数) %>
Copy after login

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); %>
Copy after login

4. For PHP pages:

Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!