为避免在点击后退按钮时出现页面过期问题,我们在每个页面中添加了以下代码。
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter("must-revalidate");
有人可以告诉我,有什么可能的缺点,或者有什么方法可以避免页面过期问题?
答案 0 :(得分:1)
使用Apache时,您不必使用PHP header()
方法。
使用Apache mod_expires模块,您可以控制服务器响应中Expires
HTTP标头和max-age
HTTP标头的Cache-Control
指令的设置。
例如,如果您希望所有网页都过期in 1 month
(并且不会被浏览器重新加载),请使用httpd.conf
文件,<VirtualHost>
部分或其中的下一个配置行.htaccess
档案:
ExpiresActive On // Enables "Expires" and "Cache-Control" headers generation
ExpiresDefault "access plus 1 month" // All resources expire after 1 month