HttpUtil.class.php (1935B)
1 <?php 2 3 class HttpUtil 4 { 5 6 /** 7 * Schickt einen HTTP-Status zum Client und beendet das Skript. 8 * 9 * @param Integer $status HTTP-Status (ganzzahlig) (Default: 501) 10 * @param String $text HTTP-Meldung (Default: 'Internal Server Error') 11 */ 12 static function sendStatus( $status=501,$text='Internal Server Error' ) 13 { 14 if ( headers_sent() ) 15 { 16 echo "$status $text\n$message"; 17 exit; 18 } 19 20 header('HTTP/1.0 '.intval($status).' '.$text); 21 header('Content-Type: text/html'); 22 echo <<<HTML 23 <html> 24 <head><title>$status $text</title></head> 25 <body> 26 <h1>$text</h1> 27 <hr> 28 <address>Bee</adddress> 29 </body> 30 </html> 31 HTML; 32 exit; 33 } 34 35 36 static function lastModified( $time ) 37 { 38 39 if ( DEVELOPMENT ) return; 40 41 // Conditional-Get eingeschaltet? 42 $lastModified = substr(date('r',$time -date('Z')),0,-5).'GMT'; 43 $etag = '"'.md5($lastModified).'"'; 44 45 // Header senden 46 header('Last-Modified: '.$lastModified ); 47 header('ETag: ' .$etag ); 48 49 // Die vom Interpreter sonst automatisch gesetzten 50 // Header uebersteuern 51 header('Cache-Control: must-revalidate'); 52 header('Pragma:'); 53 54 // See if the client has provided the required headers 55 $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : false; 56 $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH'] ) : false; 57 58 if ( !$if_modified_since && !$if_none_match ) 59 return; 60 61 // At least one of the headers is there - check them 62 if ( $if_none_match && $if_none_match != $etag ) 63 return; // etag is there but doesn't match 64 65 if ( $if_modified_since && $if_modified_since != $lastModified ) 66 return; // if-modified-since is there but doesn't match 67 68 // Der entfernte Browser bzw. Proxy holt die Seite nun aus seinem Cache 69 header('HTTP/1.0 304 Not Modified'); 70 exit; // Sofortiges Skript-Ende 71 } 72 } 73 74 75 76 77 78 ?>