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 37f4d2e21f
commit be78098065
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
*/
$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

View File

@ -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'])) {