在dir结构中搜索app配置文件是一个坏主意吗?

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?

Personally i use dirname(__FILE__) . '/path/to/config.php';

It would add some security risk. - If someone manages to place a config file "on top" you script would find this first and include / execute it... (This could range from config manipulation to some serious attack...)

Why don't you try to use the server globals? For instance:

require($_SERVER['DOCUMENT_ROOT'].'/../config.php');