Home > Backend Development > PHP Tutorial > PHP code introduction to disable page caching_PHP tutorial

PHP code introduction to disable page caching_PHP tutorial

WBOY
Release: 2016-07-13 16:59:59
Original
962 people have browsed it

The code to disable page caching in php is quite simple. Just use the php header() browser to send a Cache-Control: no-cache or set the page cache expiration time to before today.

A friend said the following is the simplest way to disable page caching

 代码如下 复制代码
header("Cache-Control: no-cache, must-revalidate");


Here I will first give you a piece of php code that can be used:

The code is as follows
 代码如下 复制代码
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
Copy code


header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");


Let’s first understand the HTTP response message. In fact, we can use the Telnet command to view it. Below I will give some HTTP response content: HTTP/1.1 200 OK

Server:Microsoft-IIS/6.0

Date: Thu, 31 Oct 2008 11:20:53 GMT

Content-Type: text/html

Set-Cookie: name=value; path=/
 代码如下 复制代码

//设置此页面的过期时间(用格林威治时间表示),只要是已经过去的日期即可。
header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");

//设置此页面的最后更新日期(用格林威治时间表示)为当天,可以强制浏览器获取最新资料
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

//告诉客户端浏览器不使用缓存,HTTP 1.1 协议
header("Cache-Control: no-cache, must-revalidate");

//告诉客户端浏览器不使用缓存,兼容HTTP 1.0 协议
header("Pragma: no-cache");
Cache-control: private


Let’s introduce it in detail below.

The code is as follows
Copy code
//Set the expiration time of this page (expressed in Greenwich Mean Time), as long as it is a date that has passed.  //Set the last updated date of this page (expressed in Greenwich Mean Time) to the current day to force the browser to obtain the latest information. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");   //Tell the client browser not to use cache, HTTP 1.1 protocol header("Cache-Control: no-cache, must-revalidate");  //Tell the client browser not to use cache and be compatible with HTTP 1.0 protocol header("Pragma: no-cache");

?> Just put the above code at the beginning of your php page, otherwise the header function may go wrong. So it must be placed at the beginning of the document. http://www.bkjia.com/PHPjc/631282.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631282.htmlTechArticleThe code to disable page caching in php is quite simple, just use the php header() browser to send a Cache-Control : no-cache or set the page cache expiration time to be before today...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template