note 58820 added to function.header

From: Date: Thu, 17 Nov 2005 04:26:01 +0000
Subject: note 58820 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-98681@lists.php.net to get a copy of this message
Using apache and mod_vhost_alias, you have the oportunity to produce some amazing websites. Take this for example: Using mod_vhost_alias, you can have apache point to your index.php file... Doing so, you can use PHP to control EVERY aspect of your website, including making "human readable paths" (mysite.com/info/contact_us/) very easily. This is done with the Apache/mod_vhost_alias directive "VirtualDocumentRoot". (eg: VirtualDocumentRoot "/www/mysite.com/index.php") However, this makes it harder to display images and documents/files you would normally have static. You will require a page to actually handle the request and load the appropriate file... A simple example: Assume URL is: http://mysite.com/images/firefox_button.png <?php $path = './images/'; $image = preg_replace('/^\/images\//i', null, $_SERVER['REQUEST_URI']); $image = str_replace('..', null, $image); $filename = $path . $image; $file_info = pathinfo($filename); $extn = $file_info['extension']; if( file_exists($filename) ) { header('Content-Type: image/'.$extn); $open = fopen($filename, 'r'); fpassthru($open); fclose($open); } else { header('HTTP/1.0 404 Not Found'); } exit(); ?> The fun thing about this, is you can also supply something like this to control a cache of these images... This will greatly lighten the load on your server: Before: header('Content-Type: image/'.$extn); Add: header('Content-Control: cache'); header('Content-Type: image/'. date('r', time()+604800)); // expire in 7 days With VirtualDocumentRoot, you can do almost _anything_... Some prime examples where using VirtualDocumentRoot would be helpful: - create, handle and manage 'human readable' URLs - potentially thwart "leeching" of media, using sessions/cookies(eg: require a hit to a specific page before any images can be loaded, etc.) - a "mod_speling" handling system - create a "wiki" style site with ease - and many, many others... just use your imagination Enjoy. :-) ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58820 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58820&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58820&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58820&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58820&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58820&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58820&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58820&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58820&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98681) next »