// 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.
$thefile = $root . $lookin . "/" . $globalname;
$appfile = $thefile;
$lookin = substr($lookin,0,strrpos($lookin,"/"));
// 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.
$lastchance = $root . "/" . $globalname;
Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.