脚本宝典收集整理的这篇文章主要介绍了php – 304:未修改和前端缓存,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我听说过使用$_SERVER [‘HTTP_IF_MODIFIED_SINCE’],但是这个变量似乎没有出现在我的$_SERVER超级数组中.
我的问题不是如何返回一个304标题,而是如何知道应该返回一个.
编辑:问题是我的$_SERVER [‘HTTP_IF_MODIFIED_SINCE’]未设置.这是我的.htaccess文件的内容:
ExpiresActive On ExpiresByTyPE image/jpeg "modification plus 1 month" ExpiresByType image/png "modification plus 1 month" ExpiresByType image/gif "modification plus 1 month" Header append Cache-Control: "must-revalidate" <IfModule mod_rewrITe.c> RewriteEngine On RewriteCond $1 !^(controller\.PHP) rewriterule (.*\.jpg|.*\.png|.*\.gif) controller.PHP/$1 </IfModule>
HTTP_IF_MODIFIED_SINCE仍然不会出现在$_SERVER超级数组中.
mod_expires
和
mod_headers
并正常工作.从
a comment on PHP.net起借:
$last_modified_time = filemtime($file); $etag = md5_file($file); // always send headers header("Last-Modified: ".gmdate("D,d M Y H:i:s",$last_modified_time)." GMT"); header("Etag: $etag"); // exit if not modified if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time || @trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { header("HTTP/1.1 304 Not Modified"); exit; } // output data
以上是脚本宝典为你收集整理的php – 304:未修改和前端缓存全部内容,希望文章能够帮你解决php – 304:未修改和前端缓存所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。