I have a php app with a configuration file in its root. If I include it by it's absolute path, then I get a problem when I move the app elsewhere. If I include it by relative path, I get a problem when I move the file where the config is included. So, I've come up with something like this to search for the app config file down the directory structure.
$relative_path = "";
for ($i=0; $i<6; $i++) {
if (file_exists($relative_path."config.php")) {
require ($relative_path."config.php");
break;
}
$relative_path .= "../";
}
Could this be a bad idea?