background image

(2)禁止页面在浏览器中被缓存。

 

如果因业务需要访问者每次都浏览页面都是得到最新的资料,而不是 Proxy   

或 cache 中

的资料,可以使用下列的标头:

查看代码打印
1 <?php  

2 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');  

3 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');  

4 header('Cache-Control: no-store, no-cache, must-revalidate');  

5 header('Cache-Control: post-check=0, pre-check=0', false );  

6 header('Pragma: no-cache'); //兼容 http1.0 和 https  

7 ?> 

其实这里主要就是设置下面几个选项的值:

CacheControl = no-cache
Pragma=no-cache
Expires = -1

当 HTTP1.1 服务器指定 CacheControl = no-cache 时,浏览器就不会缓存该网页。旧式 
HTTP 1.0 

 

服务器不能使用 Cache-Control 

 

标题。所以为了向后兼容 HTTP 1.0 服务器,IE 使

用 Pragma:no-cache 

 

标题对 HTTP 提供特殊支持。

有关 Cache-control 的具体介绍请参考本站文章:

 

网页缓存控制 Cache-control 常见的取值有 private、no-cache、max-age、must-revalidate 介绍

 

如果客户端通过安全连接 (https://) 

 

与服务器通讯,且服务器在响应中返回 Pragma:no-

cache 

 

标题,则 Internet Explorer 不会缓存此响应。注意:Pragma:no-cache 仅当在安全连接

 

中使用时才防止缓存,如果在非安全页中使用,处理方式与 Expires:-1 相同,该页将被缓
存,但被标记为立即过期。

Expires 是个好东东,如果服务器上的网页经常变化,就把它设置为-1,表示立即过期。如
果一个网页每天凌晨 1 点更新,可以把 Expires 设置为第二天的凌晨 1 点。

(3

 

)让使用者的浏览器出现找不到档案的信息。