$value) if(substr($name, 0, 5) == 'HTTP_') $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; return $headers; } } $method = $_GET['method']; // v (default, shared over all domains) u (unique, exists in images.bayofislands.net folder, not _images) if($method == 'u') { $working_path = $site_root . str_replace('http://','',$site_url_images) .'/'. $_GET['path']; } elseif($method == 'q') { // stat include('stat.php'); $working_path = $site_path_images . 'spacer.gif'; } else { $working_path = $site_path_images . $_GET['path']; } //echo '$working_path:'.$working_path;exit; $site_path = preg_replace('#\/\/?$#','/',$site_path); function go_404($point='') { global $site_url; $error_url = $site_url . '/404.php?p=2&q='.str_replace('//','/','/'.$_SERVER['REQUEST_URI']); //$error_url = $site_url.'/'.$_SERVER['REQUEST_URI'].'/404.php'; trigger_error('error in library_headers: #'.$point, E_USER_ERROR); header( "HTTP/1.1 404 Not found" ); header( "Status: 404 Error" ); header ("Location: $error_url"); return false; } //$lastModified = filemtime($working_path); $lastModified = $core_mtime; if(!$lastModified) { $lastModified = time(); } // Get client headers $request = getallheaders(); // get modifiedSince timestamp if (isset($request['If-Modified-Since'])) { $remotetime_array = explode(';', $request['If-Modified-Since']); $remotetime = strtotime($remotetime_array[0]); } else { $remotetime = 0; } // Compare time the content was last modified with client cache if (($lastModified <= $remotetime) && $method != 'q')// ie if local is older than remote { //header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); //header('ETag: "' . md5(gmdate('D, d M Y H:i:s', $lastModified) . ' GMT').'"'); header('HTTP/1.1 304 Not Modified'); exit; } # ignore paths with a '..' if (preg_match('!\.\.!', $working_path)){ go_404('a1'); } # make sure our path starts with a known directory if (!preg_match('!^(images|_images|'.$image_folder.'|favicon|'.str_replace('http://','',$site_url_images).')!', str_replace(array($site_root,'http://'),'',$working_path))){ go_404('1'); } //echo "working_path:$working_path site_root:$site_root";exit; # does the file exist? if (!file_exists($working_path)){ go_404('2'); } # output a mediatype header $ext = array_pop(explode('.', $working_path)); switch ($ext){ /* case 'css': header("Content-type: text/css"); $zip = 1; break; case 'js' : header("Content-type: text/javascript"); $zip = 1; break;*/ case 'gif': header("Content-type: image/gif"); $zip = 0; break; case 'jpg': header("Content-type: image/jpeg"); $zip = 0; break; case 'jpeg': header("Content-type: image/jpeg"); $zip = 0; break; case 'ico': header("Content-type: image/x-icon"); $zip = 0; break; case 'png': header("Content-type: image/png"); $zip = 0; break; default: go_404('3'); /*header("Content-type: text/plain"); $zip = 1;*/ break; } ob_start(); if($zip == 1) { ob_start('ob_gzhandler'); } $css_file = file_get_contents($working_path); // could add server-side caching here echo $css_file; if($zip == 1) { ob_end_flush(); } if($method != 'q') { // cache far-future header("Expires: " . gmdate("D, d M Y H:i:s", time()+315360000)." GMT"); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); //header('ETag: "' . md5(gmdate('D, d M Y H:i:s', $lastModified) . ' GMT').'"'); header('Cache-Control: max-age=315360000, public'); } else { // cache stat gif as long as a page (eg. logs 1 visitor every 10 hours) // maybe logged-in folk will trigger this to move faster? header("Expires: " . gmdate("D, d M Y H:i:s", time() + $remote_cachetime)." GMT"); header('Last-Modified: ' . gmdate("D, d M Y H:i:s", time() - ($remote_cachetime / 2)) . ' GMT'); //header('ETag: "' . md5(gmdate("D, d M Y H:i:s", time() - ($remote_cachetime / 2)) . ' GMT').'"'); header("Cache-Control: max-age=$remote_cachetime, public"); } header('Pragma: public'); header('Content-Length: ' . ob_get_length()); header('X-Powered-By: dreams and beans'); ob_end_flush(); ?>