| px | top | add code | search | signup | login | help |
<?php
/*
©1999-2000 rustang.com
rustang@rustang.com
*/
// Set some things up:
$root = $DOCUMENT_ROOT; // you could change this to wherever you want the script to stop looking, $DOCUMENT_ROOT will be the root of your domain
$globalname = "global.php"; // the filename of your special global file
// get the first directory to look in (the current request directory)
$lookin = (substr($REQUEST_URI,-1) == "/") ? dirname($REQUEST_URI . ".") : dirname($REQUEST_URI);
// now the meaty part of the search:
// look for the file in the web tree,
// starting with the current directory
// and working down to the web root.
// If the file is found, break out of
// the loop. Otherwise, go a level up
// on the directory tree and try again.
while($lookin):
$thefile = $root . $lookin . "/" . $globalname;
if(file_exists($thefile)):
$appfile = $thefile;
break;
else:
$lookin = substr($lookin,0,strrpos($lookin,"/"));
endif;
endwhile;
// now, if we found the file in the
// above loop, we'll stick it in and be
// done already. Otherwise, we still
// haven't looked in the root (because
// the loop exited as soon as $lookin
// had zero-length), so we'll look there
// and include the file if we find it.
if(!empty($appfile)):
include($appfile);
else:
$lastchance = $root . "/" . $globalname;
if(file_exists("$lastchance")):
include("$lastchance");
endif;
endif;
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.