Home > Drupal > Drupal 6 Bootstrap : Load Drupal from an external PHP script

Drupal 6 Bootstrap : Load Drupal from an external PHP script

You can load drupal into an external PHP script. The external PHP script looks like this

//change working directory to Drupal root directory
chdir('/var/www/drupal/');

//include bootstrap file
require_once 'includes/bootstrap.inc';

// bootstrap drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

/* you can then call drupal functions etc like 
 * db_query()
 * noad_load()
 */ 

$global $user; 
/* remember if you want have user login working in your external script, 
 * you need to set ( uncomment )  $cookie_domain = 'your domain name'; in the drupal settings file
 * if on localhost $cookie_domain = 'localhost'; 
 * now log into your drupal instance from a browser 
 * open a tab in the same browser and call your external PHP script 
 * the user details must be populated in $user
 */ 
 echo "<pre>;
 var_dump($user);
 echo "</pre>";
Advertisements
Categories: Drupal
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: