diff cache_check.inc @ 14:91ee5f49907e

Correct caching. We could probably push caching earlier, but more important that it is correct.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Wed, 19 Sep 2012 13:55:58 +0200
parents 6c0162497d56
children f51be7b9711a
line wrap: on
line diff
--- a/cache_check.inc	Wed Sep 19 12:42:32 2012 +0200
+++ b/cache_check.inc	Wed Sep 19 13:55:58 2012 +0200
@@ -1,17 +1,18 @@
 <?php
-if (DEBUG)
-  var_dump($_SERVER);
+function cache_check($mtime)
+{
+   if (DEBUG)
+    var_dump($_SERVER);
 
-$HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE'];
-$if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE);
+  $HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE'];
+  $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE);
 
-$SCRIPT_FILENAME=$_SERVER['SCRIPT_FILENAME'];
-$mtime = filemtime($SCRIPT_FILENAME);
-$gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
+  $gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
 
-if ($if_modified_since == $gmdate_mod) {
+  if ($if_modified_since == $gmdate_mod) {
     header("HTTP/1.0 304 Not Modified");
     exit;
+  }
+  header("Last-Modified: $gmdate_mod");
 }
-header("Last-Modified: $gmdate_mod");
 ?>
\ No newline at end of file