## ## [changes] ## - 2010.04.20 : some code-style change ## - 2009.11.12 : bug fixed header_cache() ## - 2003.09.24 : bug fixed ## - 2003.08.12 : add header_filecache() ## - 2003.06.10 : add header_nocache(), header_cache() ## - 2003.03.13 : new build ## ## [references] ## ## [usage] ## ## [example] ## function url_refresh($url, $sec=0) { echo ""; exit; } function url_header($url) { Header('Location: '.$url); exit; } ## HTML page no cache ## ## use the 'action' PHP file header ## use GMT timezone instead of system default timezone(ex KST,...) ## ## echo ''."\n"; ## echo ''."\n"; ## echo '."\n"; ## or ## session_cache_limiter('nocache'); ## session_start(); ## function header_nocache() { header('Expires: Thu, 19 Nov 1981 08:52:00 GMT'); // alway past time header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); header('Pragma: no-cache'); // HTTP/1.0 //header('Last-Modified: '.gmdate('D, d M Y H:i:s T')); // not need return TRUE; // alway true } ## HTML page cache ## ## use the 'write HTML FORM' file header ## use GMT timezone instead of system default timezone(ex KST,...) ## ## [same as] ## session_cache_limiter('private'); ## session_start(); ## ## [study] ## - if 'Expires' is futher time, then don't alway access(request) to server. ## - if 'Expires' is past time, it is alway access to server ## ## [refrences] ## - RFC 2616(HTTP/1.1) http://www.w3.org/Protocols/rfc2616/rfc2616.html ## - http://kr.php.net/manual/en/function.session-cache-limiter.php ## ## [argument] ## - $expire integer, expire seconds, default 86400 seconds(1 days), inputing time ## ## [return] ## - TRUE ## function header_cache($expire=86400) { if(!$expire || $expire <= 0) $expire = 86400; // refer to 'session.cache_expire' header('Last-Modified: '.gmdate('D, d M Y H:i:s T')); header('Cache-control: private, max-age='.$expire.', pre-check='.$expire); header('Expires: '.gmdate('D, d M Y H:i:s T',time()+$expire)); // past or future time return TRUE; // alway true } ## static or vitural image file caching ## function header_filecache($days=1, $file='') { global $_SERVER; // for PHP/4.0.x if($file && !@file_exists($file)) return FALSE; $term = (int)$days; // alway $days > 0 $req = $_SERVER['HTTP_IF_MODIFIED_SINCE']; // request modified datetime $time = array(); $time['expire'] = $term * 86400; // expire term, after cached $time['client'] = $term * 300; // client 'think time', or keepalive if($file) { $time['cur'] = $time['chk'] = @filemtime($file); } else { $time['cur'] = time(); // virual file mtime $time['chk'] = $time['cur'] - $time['expire']; } if($req && strtotime($req)>=$time['chk']) header('HTTP/1.1 304 Not Modified'); header('Expires: '.gmdate('D, d M Y H:i:s T',$time['cur']+$time['expire'])); header('Last-Modified: '.gmdate('D, d M Y H:i:s T',$time['cur'])); // GMT header('Cache-control: private, max-age='.$time['client'].', pre-check='.$time['client']); return TRUE; // alway true } ## self print a image ## function check_redirect_image() { global $_SERVER; // for PHP/4.0.x if(!$_SERVER['PATH_INFO']) return; list(,$type,$color) = explode('/',$_SERVER['PATH_INFO']); if(!preg_match('/^im/i',$type)) return; // img, IMG, Img, images, image, ... ## check 304 HTTP status code ## header_filecache(2); // term of 2 days $color = preg_replace('/\.[^.]*$/','',strtolower($color)); ## base64 encoded images ## http://linuxchannel.net/board/read.php?table=alpha&no=75 ## 1 x 1, width:height, for center ## $images['null'] = 'R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['pureblue'] = 'R0lGODlhAQABAIAAAD13swAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; /*** $images['blue'] = 'R0lGODlhAQABAIAAAAAA/wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['darkblue'] = 'R0lGODlhAQABAIAAAEpYogAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['brown'] = 'R0lGODlhAQABAIAAAHsAAAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['green'] = 'R0lGODlhAQABAIAAAAB9RQAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['grey'] = 'R0lGODlhAQABAIAAAOjs6AAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['lightgrey']= 'R0lGODlhAQABAIAAANHY0gAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['darkgrey'] = 'R0lGODlhAQABAIAAAIycjwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['margenta'] = 'R0lGODlhAQABAIAAANsAmgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['red'] = 'R0lGODlhAQABAIAAANxEHAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; $images['yellow'] = 'R0lGODlhAQABAIAAAP/3AAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; ***/ ## 1 x 9, width:9, for width ## $images['brown'] = 'R0lGODlhAQABAIAAAH8AAP///ywAAAAAAQABAAACAkQBADs='; $images['blue'] = 'R0lGODlhAQAJAJEAAAAAAP///wAA/zc/PywAAAAAAQAJAAACA5RvUwA7'; $images['green'] = 'R0lGODlhAQAJAJEAAAAAAP///zc/PzF6CywAAAAAAQAJAAACA5xvUgA7'; $images['margenta'] = 'R0lGODlhAQAJAJEAAAAAAP///9MAizc/PywAAAAAAQAJAAACA5RvUwA7'; $images['yellow'] = 'R0lGODlhAQAJAJEAAAAAAP///zc/P/v8nywAAAAAAQAJAAACA5xvUgA7'; ## 9 x 1, 9:height, for height ## $images['h_pureblue'] = 'R0lGODlhCQABAIAAAD13szdQRSH5BAAAAAAALAAAAAAJAAEAAAIDhG9RADs='; if(!$images[$color]) $color = 'null'; header('Content-type: image/gif'); echo base64_decode($images[$color]); exit; // don't print any messages } ?>