view cache_check.inc @ 28:ca75a735651e

Bug fix: Remove superfluous print statement. Use include_once.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Sun, 30 Sep 2012 03:36:02 +0200
parents 1ec0738a1623
children 7b19be62ea94
line wrap: on
line source

<?php
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);

  $gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';

  if ($if_modified_since == $gmdate_mod) {
    header("HTTP/1.0 304 Not Modified");
    exit;
  }
  header("Last-Modified: $gmdate_mod");
}

function cache_time($path)
{
  global $newest;
  $mtime = filemtime($path);
  if ($mtime > $newest) {
    $newest = $mtime;
  }
}

function include_with_mtime($path)
{
  cache_time($path);
  include_once($path);
}

cache_time(__FILE__);
?>