Drupal 7 Bootstrap : Load Drupal from an external PHP script

Naveen S Nayak's Blog

This is how to load or bootstrap Drupal 7 into an external script.

We are doing a full Drupal bootstrap here. There are many phases which you can bootstrap, for eg bootstrap only the database layer. You can read about them on the Drupal site

// display all errors
error_reporting(E_ALL);
ini_set("display_errors", 1);

// drupal root and include
define('DRUPAL_ROOT', '/path/to/drupal');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

// you might need to define some of these if the script is not called from a webpage
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';             // required, else drupal will complain
$_SERVER['HTTP_HOST'] = 'www.mysitename.com:8888'; // optional but required for multi site configs
$_SERVER['REQUEST_METHOD'] = 'GET';                // optional
$_SERVER['SCRIPT_NAME'] = '/' . basename(__FILE__);// optional

// Load Drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// Drupal is fully loaded and all Drupal functions are available - your code goes here

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s