Heim  >  Artikel  >  Backend-Entwicklung  >  php静态文件怎么返回304?提示页面未更新

php静态文件怎么返回304?提示页面未更新

WBOY
WBOYOriginal
2016-07-25 08:52:181022Durchsuche
  1. private function _addEtag($file) {
  2. $last_modified_time = filemtime($file);
  3. $etag = md5_file($file);
  4. // always send headers
  5. header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
  6. header("Etag: $etag");
  7. // exit if not modified
  8. if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
  9. @trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
  10. header("HTTP/1.1 304 Not Modified");
  11. exit;
  12. }
  13. }
复制代码

说明: 此函数,可以在静态文件(如图片)输出之前调用即可。



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn