Home  >  Article  >  php教程  >  PHP 浏览器缓存的各种操作方法

PHP 浏览器缓存的各种操作方法

WBOY
WBOYOriginal
2016-06-13 10:04:051156browse

PHP 中的 header() 函数,发送特定的缓存控制原始 HTTP 标头,header() 必须在任何实际输出之前调用,不论是来自普通的 HTML 标记,空行或者 PHP。在中文环境下,一个全角的空格也会导致难以查找的错误

 代码如下 复制代码
 
//下面的语句设置此页面的过期时间(用格林威治时间表示),只要是已经过去的日期即可。
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"); 
 
?>
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