Skip to content

Instantly share code, notes, and snippets.

@billcreswell
Forked from miwebguy/style.php
Created June 26, 2014 01:51
Show Gist options
  • Save billcreswell/dec7ab1717dedaa90571 to your computer and use it in GitHub Desktop.
Save billcreswell/dec7ab1717dedaa90571 to your computer and use it in GitHub Desktop.
<?php
/**
* Adding Cache Headers and ETag to example: http://sperling.com/examples/pcss/
*/
class PHPStyle
{
public static function setHeaders($filename="style.css",$type="text/css")
{
$mod = date ("Y-m-d::H:i:s.", getlastmod());
$etag = $filename.$mod;
$headers = apache_request_headers();
$isCached = isset($headers['If-None-Match']) && $headers['If-None-Match']==$etag;
header("Content-type: $type");
if ($isCached) {
header('HTTP/1.1 304 Not Modified');
header("Cache-Control: max-age=604800");
header("Pragma: cache");
header("ETag: $etag");
die();
} else {
header("Etag: $etag");
header("Pragma: cache");
header("Cache-Control: max-age=604800");
header("Content-Disposition: inline; filename=\"$filename\"");
}
}
}
$test = PHPStyle::setHeaders();
$blue = "blue";
$green = "green";
$sheet = <<<CSS
/* --- start of css --- */
h1 {
color: $blue;
font-weight: bold;
font-size: 1.2em;
text-align: left;
}
h2 {
color:$green;
}
/* --- end of css --- */
CSS;
echo $sheet;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment