note 67945 added to function.virtual

From: Date: Fri, 07 Jul 2006 10:26:56 +0000
Subject: note 67945 added to function.virtual
Groups: php.notes 
Request: Send a blank email to php-notes+get-114534@lists.php.net to get a copy of this message
You can use virtual() to implement your own dispatcher/auth handler in an efficient and effective way. For instance if you have a bunch of images you would like to be served statically by Apache (its job after all), but with a more com plex access pattern than mod_access allows you to do (say a MySQL lookup with your app logic), try this simple Apache rule: Order Allow,Deny Allow from env=PHP_ALLOW Then in your PHP script, before sending any content or header: <?php $image = "/some/URL/path/test.png"; if (client_may_view_image($image)) { apache_setenv('PHP_ALLOW', '1'); if (virtual($image)) exit(0); echo "Ops, failed to fetched granted image $image (hammer your webmaster).\n"; } else echo "Sorry buddy, you're not allowed in here.\n"; ?> Of course very Apache-ish, but it's much more efficient and uniform to rely on Apache rather than passthru() and mime_content_type() hacks : it does the path lookup and auth/security audit as the admin expects, use the best static serving it can (think 'sendfile') and you can even chain your request with another embedded script eg. in mod_perl. ---- Server IP: 217.174.203.10 Probable Submitter: 81.57.189.209 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.virtual.php Edit -- http://master.php.net/note/edit/67945 Del: integrated -- http://master.php.net/note/delete/67945/integrated Del: useless -- http://master.php.net/note/delete/67945/useless Del: bad code -- http://master.php.net/note/delete/67945/bad+code Del: spam -- http://master.php.net/note/delete/67945/spam Del: non-english -- http://master.php.net/note/delete/67945/non-english Del: in docs -- http://master.php.net/note/delete/67945/in+docs Del: other reasons-- http://master.php.net/note/delete/67945 Reject -- http://master.php.net/note/reject/67945 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114534) next »