Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 缓存控制和页面过期问题_Php_Html_Header_Cache Control - Fatal编程技术网

Php 缓存控制和页面过期问题

Php 缓存控制和页面过期问题,php,html,header,cache-control,Php,Html,Header,Cache Control,为了避免在点击后退按钮时出现页面过期问题,我们在每个页面中添加了以下代码 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"); 有人能

为了避免在点击后退按钮时出现页面过期问题,我们在每个页面中添加了以下代码

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");

有人能告诉我,可能的缺点是什么,或者有什么方法可以避免页面过期问题?

使用Apache时,您不必使用PHP
header()
方法

使用Apache模块,您可以控制服务器响应中
Expires
HTTP头和
Cache Control
HTTP头的
max age
指令的设置

例如,如果您希望所有页面在1个月内过期(且不被浏览器重新加载),请在
httpd.conf
文件、
部分或
.htaccess
文件中使用下一个配置行:

ExpiresActive On // Enables "Expires" and "Cache-Control" headers generation
ExpiresDefault "access plus 1 month" // All resources expire after 1 month

但是上次修改的日期将始终是当前日期…@MihaiIorga是的,但这是在修复文档过期问题…您已使页面在过去过期。浏览器将不得不更新它。您使用什么web服务器?@webbandit我们使用的是Apache我们的目标不是缓存,而是在单击“上一步”按钮时避免页面过期问题。这段代码正在解决这个问题,但是想知道使用这段代码是否有缺点没有缺点,这是最好的方法,因为你的php脚本会像往常一样运行,你不必退出。阿帕奇会为你做一切。