Arbitrary placement of _ss_environment.php in parent folders

Removes hardcoding to three levels
This commit is contained in:
Daniel Hensby 2013-01-18 13:50:24 +00:00 committed by Ingo Schommer
parent f45621b07e
commit 9a6a6ec75d
2 changed files with 28 additions and 16 deletions

View File

@ -46,19 +46,22 @@ error_reporting(E_ALL | E_STRICT);
/** /**
* Include _ss_environment.php files * Include _ss_environment.php files
*/ */
$envFiles = array( //define the name of the environment file
'_ss_environment.php', $envFile = '_ss_environment.php';
'../_ss_environment.php', //define the dir to start scanning from (have to add the trailing slash)
'../../_ss_environment.php', $dir = '.';
'../../../_ss_environment.php'); //check this dir and every parent dir (until we hit the base of the drive)
do {
foreach($envFiles as $envFile) { $dir = realpath($dir) . '/';
if(@file_exists($envFile)) { //if the file exists, then we include it, set relevant vars and break out
define('SS_ENVIRONMENT_FILE', $envFile); if (file_exists($dir . $envFile)) {
include_once($envFile); define('SS_ENVIRONMENT_FILE', $dir . $envFile);
include_once(SS_ENVIRONMENT_FILE);
break; 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 // GLOBALS AND DEFINE SETTING

View File

@ -31,15 +31,24 @@ if (function_exists('session_start')) {
// Include environment files // Include environment files
$usingEnv = false; $usingEnv = false;
$envFileExists = false; $envFileExists = false;
$envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php'); //define the name of the environment file
foreach($envFiles as $envFile) { $envFile = '_ss_environment.php';
if(@file_exists($envFile)) { //define the dir to start scanning from
include_once($envFile); $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; $envFileExists = true;
//legacy variable assignment
$usingEnv = true; $usingEnv = true;
break; 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($envFileExists) {
if(!empty($_REQUEST['useEnv'])) { if(!empty($_REQUEST['useEnv'])) {