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.
header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");
//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");
|