Drupal: Simple way to bootstrap scripts into Drupal system

Previously I wrote about a method of hooking up an existing site with the Drupal backend. That will work fine if the request comes from the browser, but for a script you will need an extra little bit of configuration.

In conjuction with initialise_drupal_bootstrap() (a function provided in the previous post), you will need to call the following.

function initialise_for_script($server_address = 'yoursite.com') {
global $_SERVER;

// define default settings
$_SERVER['HTTP_HOST'] = $server_address;
$_SERVER['PHP_SELF'] = '/index.php';

When using the bootstrappers, your script would look something like this:

* Run this from your Drupal folder.
* Usage: php scripts/mailout.php


if (function_exists(mailout_loop')) {
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog