diff --git a/core/Core.php b/core/Core.php index e23eadbb9..0ff5d2425 100644 --- a/core/Core.php +++ b/core/Core.php @@ -46,19 +46,22 @@ error_reporting(E_ALL | E_STRICT); /** * Include _ss_environment.php files */ -$envFiles = array( - '_ss_environment.php', - '../_ss_environment.php', - '../../_ss_environment.php', - '../../../_ss_environment.php'); - -foreach($envFiles as $envFile) { - if(@file_exists($envFile)) { - define('SS_ENVIRONMENT_FILE', $envFile); - include_once($envFile); +//define the name of the environment file +$envFile = '_ss_environment.php'; +//define the dir to start scanning from (have to add the trailing slash) +$dir = '.'; +//check this dir and every parent dir (until we hit the base of the drive) +do { + $dir = realpath($dir) . '/'; + //if the file exists, then we include it, set relevant vars and break out + if (file_exists($dir . $envFile)) { + define('SS_ENVIRONMENT_FILE', $dir . $envFile); + include_once(SS_ENVIRONMENT_FILE); break; } -} +//here we need to check that the real path of the last dir and the next one are +// not the same, if they are, we have hit the root of the drive +} while (realpath($dir) != realpath($dir .= '../')); /////////////////////////////////////////////////////////////////////////////// // GLOBALS AND DEFINE SETTING diff --git a/dev/install/install.php5 b/dev/install/install.php5 index d3ec3783e..59fb35fa3 100644 --- a/dev/install/install.php5 +++ b/dev/install/install.php5 @@ -31,15 +31,24 @@ if (function_exists('session_start')) { // Include environment files $usingEnv = false; $envFileExists = false; -$envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php'); -foreach($envFiles as $envFile) { - if(@file_exists($envFile)) { - include_once($envFile); +//define the name of the environment file +$envFile = '_ss_environment.php'; +//define the dir to start scanning from +$dir = '.'; +//check this dir and every parent dir (until we hit the base of the drive) +do { + $dir = realpath($dir) . '/'; + //if the file exists, then we include it, set relevant vars and break out + if (file_exists($dir . $envFile)) { + include_once($dir . $envFile); $envFileExists = true; + //legacy variable assignment $usingEnv = true; break; } -} +//here we need to check that the real path of the last dir and the next one are +// not the same, if they are, we have hit the root of the drive +} while (realpath($dir) != realpath($dir .= '../')); if($envFileExists) { if(!empty($_REQUEST['useEnv'])) {