note 61507 added to function.virtual
| From: | ruibal_DELETED_p*AT*gmail__dot__com at osu1 dot php dot net | Date: | Sun, 05 Feb 2006 23:04:10 +0000 |
| Subject: | note 61507 added to function.virtual | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103058@lists.php.net to get a copy of this message | ||
when php is installed as an apache module, this works pretty well for writing your own php
preprocessor/information logger. For example, requests to any URI underneath pre.php will first be
executed by pre.php, then returned to the user.
<?
$docroot = $_SERVER['DOCUMENT_ROOT'];
$script_root = str_replace(
basename($_SERVER['SCRIPT_NAME']),'',$_SERVER['SCRIPT_NAME'] );
$script_ext = substr( $_SERVER['SCRIPT_NAME'], strrpos(
$_SERVER['SCRIPT_NAME'],'.' ) );
$fakework_root = $script_root.basename( $_SERVER['SCRIPT_NAME'] ).'/';
$framework_root = $script_root.'_'.basename( $_SERVER['SCRIPT_NAME'],
$script_ext ).'/';
$frequest_root = dirname( $framework_root.substr( $_SERVER['PATH_INFO'], 1
)).'/';
$frequest_name = basename( $_SERVER['PATH_INFO'] );
$frequest_ext = (strrpos($frequest_name,'.')===FALSE ? FALSE : strtolower(substr(
$frequest_name, ( strrpos( $frequest_name, '.' )+1 ) ) ) );
$frequest_full = $frequest_root.$frequest_name;
$doc_frequest = $docroot.$frequest_full;
$doc_framework = $docroot.$framework_root;
$DO_PARSE = in_array( $frequest_ext, $chk_exts );
if( $DO_PARSE )
{
$tmpfname = tempnam( $doc_framework.'tmp', 'aj_' ).($frequest_ext?
('.'.$frequest_ext) : '');
if( ($to_parse=@file_get_contents($doc_frequest))===FALSE )
$to_parse="404";
$tmpvname = str_replace( $docroot, '', $tmpfname );
$tmpvname = str_replace( '\\\\', '/', $tmpvname );
// - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Do processing of data stored in $to_parse
// - - - - - - - - - - - - - - - - - - - - - - - - - - -
$to_parse = striptags( $to_parse );
// - - - - - - - - - - - - - - - - - - - - - - - - - - -
$handle = fopen($tmpfname, "w");
fwrite($handle, $to_parse);
fclose($handle);
@virtual( $tmpvname.$getvars );
unlink( $tmpfname );
}
else
@virtual( $frequest_full.$getvars );
?>
So all files in http://server/sub/pre.php/path/ are
really located in http://server/sub/_pre/path/
All this needs is some kind of caching mechanism.
But yeah, this could be modified to add watermarks with the image functions, convert to xml with
Tidy, check for extensions better with mimeTypes, proxy content with cURL, validate
$_SERVER['HTTP_REFERER'] or $_SERVER['HTTP_USER_AGENT'], etc etc
This gives you much more over than the auto_prepend_file, and auto_append_file, for certain
functionality
The key is the virtual function _because_ it delivers the modified content with an apache
subrequest.
----
Server IP: 216.194.113.175
Probable Submitter: 67.172.174.7
----
Manual Page -- http://www.php.net/manual/en/function.virtual.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61507
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61507&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61507&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61507&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61507&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61507&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61507&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61507&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61507&report=yes
Search -- http://master.php.net/manage/user-notes.php