You are here

function conf_init in Drupal 4

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

Loads the configuration and sets the base URL correctly.

1 call to conf_init()
_drupal_bootstrap in includes/bootstrap.inc

File

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

Code

function conf_init() {
  global $db_url, $db_prefix, $base_url, $base_path, $base_root, $conf;
  $conf = array();
  require_once './' . conf_path() . '/settings.php';
  if (isset($base_url)) {

    // Parse fixed base URL from settings.php.
    $parts = parse_url($base_url);
    if (!isset($parts['path'])) {
      $parts['path'] = '';
    }
    $base_path = $parts['path'] . '/';

    // Build $base_root (everything until first slash after "scheme://").
    $base_root = substr($base_url, 0, strlen($base_url) - strlen($parts['path']));
  }
  else {

    // Create base URL
    $base_root = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';

    // As $_SERVER['HTTP_HOST'] is user input, ensure it only contains
    // characters allowed in hostnames.
    $base_url = $base_root .= '://' . preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);

    // $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not
    // be modified by a visitor.
    if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\\,/')) {
      $base_path = "/{$dir}";
      $base_url .= $base_path;
      $base_path .= '/';
    }
    else {
      $base_path = '/';
    }
  }
}