} } // Write the resized image to the cache $outputFunction($dst, $resized, $quality); // Put the data of the resized image into a variable ob_start(); $outputFunction($dst, null, $quality); $data = ob_get_contents(); ob_end_clean(); // Clean up the memory ImageDestroy($src); ImageDestroy($dst); // See if the browser already has the image $lastModifiedString = gmdate('D, d M Y H:i:s', filemtime($resized)) . ' GMT'; $etag = md5($data); doConditionalGet($etag, $lastModifiedString); // Send the image to the browser with some delicious headers header("Content-type: {$mime}"); header('Content-Length: ' . strlen($data)); echo $data; function findSharp($orig, $final) { $final = $final * (750.0 / $orig); $a = 52; $b = -0.27810650887573124; $c = 0.00047337278106508946; $result = $a + $b * $final + $c * $final * $final; return max(round($result), 0); } // findSharp() function doConditionalGet($etag, $lastModified)
// http://fishbowl.pastiche.org/archives/001132.html $last_modified = substr(date('r', $timestamp), 0, -5) . 'GMT'; $etag = '"' . md5($last_modified) . '"'; // Send the headers header("Last-Modified: {$last_modified}"); header("ETag: {$etag}"); // See if the client has provided the required headers $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : false; $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : false; if (!$if_modified_since && !$if_none_match) { return; } // At least one of the headers is there - check them if ($if_none_match && $if_none_match != $etag) { return; // etag is there but doesn't match } if ($if_modified_since && $if_modified_since != $last_modified) { return; // if-modified-since is there but doesn't match } // Nothing has changed since their last request - serve a 304 and exit header('HTTP/1.0 304 Not Modified'); exit; } date_default_timezone_set("UTC"); doConditionalGet(filemtime('f.js')); header('Content-Type: text/javascript; charset=UTF-8'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 29030400) . ' GMT'); Header('Cache-Control: max-age=29030400, public'); require 'f.js';
imagedestroy($sourceImage); imagedestroy($destination_image); /* * Write the just edited image into the Xoops cache */ $cached_image['edited_image_filename'] = $edited_image_filename; $cached_image['image_data'] = $imageData; $cached_image['cached_time'] = $imageCreatedTime; XoopsCache::write($edited_image_filename, $cached_image); /* * Send the edited image to the browser */ // See if the browser already has the image $last_modified_string = gmdate('D, d M Y H:i:s', $imageCreatedTime) . ' GMT'; $etag = md5($imageData); doConditionalGet($etag, $last_modified_string); header('HTTP/1.1 200 OK'); // if image is cacheable if (!isset($_GET['nocache']) && !isset($_GET['nobrowsercache'])) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $imageCreatedTime) . 'GMT'); header('Cache-control: max-age=31536000'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . 'GMT'); } else { // "Kill" the browser cache header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // past date header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 header('Cache-Control: post-check=0, pre-check=0', false);
doConditionalGet($_GET["getimage"], gmmktime(1, 0, 0, 1, 1, 2004)); $imageDataRaw = base64_decode($imageDataEnc); Header("Content-Type: image/gif"); Header("Content-Length: " . strlen($imageDataRaw)); Header("Cache-Control: public, max-age={$maxAge}, must-revalidate"); Header("Expires: " . createHTTPDate(time() + $maxAge)); echo $imageDataRaw; } die; } // handle thumbnail creation if ($_GET["thumbnail"] != "") { global $thumbnailHeight, $cacheThumbnails; $thumbnailCacheSubdir = ".snifthumbs"; $file = safeDirectory(urldecode($_GET["thumbnail"])); doConditionalGet($_GET["thumbnail"], filemtime($file)); $thumbDir = dirname($file) . "/" . $thumbnailCacheSubdir; $thumbFile = $thumbDir . "/" . basename($file); if ($cacheThumbnails) { if (file_exists($thumbDir)) { if (!is_dir($thumbDir)) { $cacheThumbnails = false; } } else { if (@mkdir($thumbDir)) { chmod($thumbDir, "0777"); } else { $cacheThumbnails = false; } } if (file_exists($thumbFile)) {
/** * Turns on caching and checks if there is a recent version of this feed in the cache. * If there is, an HTTP redirect header is sent. * To effectively use caching, you should create the FeedCreator object and call this method * before anything else, especially before you do the time consuming task to build the feed * (web fetching, for example). * When appropriate, returns HTTP 304 Not Modified instead of file. * @since 1.4 * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) */ function useCached($filename = "", $timeout = 3600) { $this->_timeout = $timeout; if ($filename == "") { $filename = $this->_generateFilename(); } if (file_exists($filename) and time() - filemtime($filename) < $timeout) { // But first: Conditional GET: Use HTTP 1.1 field to see if client already has latest version doConditionalGet(filemtime($filename)); // May exit $this->_redirect($filename); } }
if (!preg_match("/{$check}/", $realpath) && !$missing) { header("HTTP/1.0 403 Forbidden"); echo " forbidden!"; exit; } if (!is_readable($image) || $missing) { //file does not exists $image = ONXSHOP_PROJECT_DIR . "public_html/share/images/missing_image.png"; header("HTTP/1.0 404 Not Found"); // log it } /** * read file info */ $image_type = exif_imagetype($image); $modified = filemtime($image); $length = filesize($image); /** * send to the client */ if ($image_type) { header("Content-type: " . image_type_to_mime_type($image_type)); header("Content-Length: " . $length); doConditionalGet($modified); readfile($image); } else { //file is not image, attempt to hack? header("HTTP/1.0 403 Forbidden"); echo "not an image"; // TODO: log it }
// etag is there but doesn't match } if ($if_modified_since && $if_modified_since != $last_modified) { return; // if-modified-since is there but doesn't match } // Nothing has changed since their last request - serve a 304 and exit header('HTTP/1.0 304 Not Modified'); exit; } $ddd = filemtime($file); $nnn = filemtime($_SERVER['SCRIPT_FILENAME']); if ($nnn > $ddd) { doConditionalGet($nnn); } else { doConditionalGet($ddd); } header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 300) . ' GMT'); Header('Cache-Control: max-age=300, public'); if ($func == '') { $func = 'e^x'; $showbox = true; } header('X-UA-Compatible: chrome=1'); header('Content-Type: text/html; charset=UTF-8'); $cf = false; $msie = false; //$mac=false; if (!(strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') === false)) { $msie = true; }