You are here

function _drupal_bootstrap in Drupal 6

Same name and namespace in other branches
  1. 4 includes/bootstrap.inc \_drupal_bootstrap()
  2. 5 includes/bootstrap.inc \_drupal_bootstrap()
1 call to _drupal_bootstrap()
drupal_bootstrap in includes/bootstrap.inc
A string describing a phase of Drupal to load. Each phase adds to the previous one, so invoking a later phase automatically runs the earlier phases too. The most important usage is that if you want to access the Drupal database from a script without…

File

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

Code

function _drupal_bootstrap($phase) {
  global $conf;
  switch ($phase) {
    case DRUPAL_BOOTSTRAP_CONFIGURATION:
      drupal_unset_globals();

      // Start a page timer:
      timer_start('page');

      // Initialize the configuration
      conf_init();
      break;
    case DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE:

      // Allow specifying special cache handlers in settings.php, like
      // using memcached or files for storing cache information.
      require_once variable_get('cache_inc', './includes/cache.inc');

      // If the page_cache_fastpath is set to TRUE in settings.php and
      // page_cache_fastpath (implemented in the special implementation of
      // cache.inc) printed the page and indicated this with a returned TRUE
      // then we are done.
      if (variable_get('page_cache_fastpath', FALSE) && page_cache_fastpath()) {
        exit;
      }
      break;
    case DRUPAL_BOOTSTRAP_DATABASE:

      // Initialize the default database.
      require_once './includes/database.inc';
      db_set_active();

      // Allow specifying alternate lock implementations in settings.php, like
      // those using APC or memcached.
      require_once variable_get('lock_inc', './includes/lock.inc');
      lock_init();
      break;
    case DRUPAL_BOOTSTRAP_ACCESS:

      // Deny access to hosts which were banned - t() is not yet available.
      if (drupal_is_denied('host', ip_address())) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
        print 'Sorry, ' . check_plain(ip_address()) . ' has been banned.';
        exit;
      }
      break;
    case DRUPAL_BOOTSTRAP_SESSION:
      require_once variable_get('session_inc', './includes/session.inc');
      session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy_sid', 'sess_gc');
      session_start();
      break;
    case DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE:

      // Initialize configuration variables, using values from settings.php if available.
      $conf = variable_init(isset($conf) ? $conf : array());

      // Sanitize the destination parameter (which is often used for redirects)
      // to prevent open redirect attacks leading to other domains. Sanitize
      // both $_GET['destination'] and $_REQUEST['destination'] to protect code
      // that relies on either, but do not sanitize $_POST to avoid interfering
      // with unrelated form submissions. $_REQUEST['edit']['destination'] is
      // also sanitized since drupal_goto() will sometimes rely on it, and
      // other code might therefore use it too. The sanitization happens here
      // because menu_path_is_external() requires the variable system to be
      // available.
      if (isset($_GET['destination']) || isset($_REQUEST['destination']) || isset($_REQUEST['edit']['destination'])) {

        // If the destination is an external URL, remove it.
        if (isset($_GET['destination']) && menu_path_is_external($_GET['destination'])) {
          unset($_GET['destination']);
          unset($_REQUEST['destination']);
        }

        // If there's still something in $_REQUEST['destination'] that didn't
        // come from $_GET, check it too.
        if (isset($_REQUEST['destination']) && (!isset($_GET['destination']) || $_REQUEST['destination'] != $_GET['destination']) && menu_path_is_external($_REQUEST['destination'])) {
          unset($_REQUEST['destination']);
        }

        // Check $_REQUEST['edit']['destination'] separately.
        if (isset($_REQUEST['edit']['destination']) && menu_path_is_external($_REQUEST['edit']['destination'])) {
          unset($_REQUEST['edit']['destination']);
        }
      }
      $cache_mode = variable_get('cache', CACHE_DISABLED);

      // Get the page from the cache.
      $cache = $cache_mode == CACHE_DISABLED ? '' : page_get_cache();

      // If the skipping of the bootstrap hooks is not enforced, call hook_boot.
      if (!$cache || $cache_mode != CACHE_AGGRESSIVE) {

        // Load module handling.
        require_once './includes/module.inc';
        bootstrap_invoke_all('boot');
      }

      // If there is a cached page, display it.
      if ($cache) {
        drupal_page_cache_header($cache);

        // If the skipping of the bootstrap hooks is not enforced, call hook_exit.
        if ($cache_mode != CACHE_AGGRESSIVE) {
          bootstrap_invoke_all('exit');
        }

        // We are done.
        exit;
      }

      // Prepare for non-cached page workflow.
      drupal_page_header();
      break;
    case DRUPAL_BOOTSTRAP_LANGUAGE:
      drupal_init_language();
      break;
    case DRUPAL_BOOTSTRAP_PATH:
      require_once './includes/path.inc';

      // Initialize $_GET['q'] prior to loading modules and invoking hook_init().
      drupal_init_path();
      break;
    case DRUPAL_BOOTSTRAP_FULL:
      require_once './includes/common.inc';
      _drupal_bootstrap_full();
      break;
  }
}