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.