Skip to content

Instantly share code, notes, and snippets.

@johnlettman-old
Created August 14, 2011 00:26

Revisions

  1. johnlettman-old created this gist Aug 14, 2011.
    21 changes: 21 additions & 0 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <?php
    $_HEADERS = apache_request_headers(); # Get client headers.
    $updateTime = strtotime('yesterday'); # Makes sure that it always caches.

    /*
    Mock page content.
    Change this after first view. If refreshing
    shows the old content, then the test worked!
    */

    $content = 'test!';

    if(isset($_HEADERS['If-Modified-Since']) && (strtotime($_HEADERS['If-Modified-Since']) == $updateTime)) {
    // Unmodified!
    header('Last-Modified: '.gmdate('D, d M Y H:i:s', $updateTime).' GMT', true, 304);
    exit;
    } else {
    // Modified or unsupported!
    header('Last-Modified: '.gmdate('D, d M Y H:i:s', $updateTime).' GMT', true, 200);
    echo $content;
    }