Same name and namespace in other branches
  1. 4.7.x includes/bootstrap.inc \conf_init()
  2. 5.x includes/bootstrap.inc \conf_init()
  3. 6.x includes/bootstrap.inc \conf_init()

Locate the appropriate configuration file.

Try finding a matching configuration directory by stripping the website's hostname from left to right and pathname from right to left. The first configuration file found will be used, the remaining will ignored. If no configuration file is found, return a default value '$confdir/default'.

Example for a fictitious site installed at http://www.drupal.org/mysite/test/ the 'settings.php' is searched in the following directories:

1. $confdir/www.drupal.org.mysite.test 2. $confdir/drupal.org.mysite.test 3. $confdir/org.mysite.test

4. $confdir/www.drupal.org.mysite 5. $confdir/drupal.org.mysite 6. $confdir/org.mysite

7. $confdir/www.drupal.org 8. $confdir/drupal.org 9. $confdir/org

10. $confdir/default

2 calls to conf_init()
bootstrap.inc in includes/bootstrap.inc
Functions that need to be loaded on every Drupal request.
system_listing in modules/system.module
Returns an array of files objects of the given type from both the site-wide directory (i.e. modules/) and site-specific directory (i.e. sites/somesite/modules/). The returned array will be keyed using the key specified (name, basename, filename). …

File

includes/bootstrap.inc, line 43
Functions that need to be loaded on every Drupal request.

Code

function conf_init() {
  static $conf = '';
  if ($conf) {
    return $conf;
  }
  $confdir = 'sites';
  $uri = explode('/', $_SERVER['PHP_SELF']);
  $server = explode('.', rtrim($_SERVER['HTTP_HOST'], '.'));
  for ($i = count($uri) - 1; $i > 0; $i--) {
    for ($j = count($server); $j > 0; $j--) {
      $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
      if (file_exists("{$confdir}/{$dir}/settings.php")) {
        $conf = "{$confdir}/{$dir}";
        return $conf;
      }
    }
  }
  $conf = "{$confdir}/default";
  return $conf;
}