php如何设置304报错(代码介绍)

2025年03月01日 建站教程

php如何设置304报错代码介绍,下面web建站小编利用php中的HTTP_IF_MODIFIED_SINCE结合etag来实现这个方法!

实现代码如下:

private function _addEtag($file) {
  $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;
  }
}

本文链接:http://so.lmcjl.com/news/24077/

展开阅读全文
相关内容