Mercurial > SimpleWebPresenter
view cache_check.inc @ 32:7b19be62ea94
Remove yet another global, replace by CacheTimeCheck class.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 04 Oct 2012 19:46:11 +0200 |
| parents | 1ec0738a1623 |
| children |
line wrap: on
line source
<?php class CacheTimeCheck { private $newest; private $files = array(); function __construct($minTime = 0, $filename = False) { if ($filename) array_push($this->files, $filename); $this->newest = $minTime; $this->cache_time(__FILE__); } function CheckHttpModified() { if (DEBUG) var_dump($_SERVER); $HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE']; $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE); $gmdate_mod = gmdate('D, d M Y H:i:s', $this->newest) . ' GMT'; if ($if_modified_since == $gmdate_mod) { header("HTTP/1.0 304 Not Modified"); exit; } header("Last-Modified: $gmdate_mod"); } function cache_time($path) { array_push($this->files, $path); $mtime = filemtime($path); if ($mtime > $this->newest) { $this->newest = $mtime; } } function includeOnce($path) { $this->cache_time($path); include_once($path); } } ?>
