Home  >  Article  >  Backend Development  >  How do php static files return 304? Prompt page has not been updated

How do php static files return 304? Prompt page has not been updated

WBOY
WBOYOriginal
2016-07-25 08:52:181071browse
  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. }
Copy code

Instructions: This function can be called before static files (such as pictures) are output.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn