Calling Drupal functions in external PHP file

Dijo David picture Dijo David · Jun 29, 2011 · Viewed 13.8k times · Source

How can I call a Drupal function or get the global variable in a PHP file which is located under the drupal installation folder. I doing it for the first time. Are there any files I need to include in my code in order to access the Drupal function or variables?

Answer

Alexey picture Alexey · Jul 18, 2011

If the above explained example doesn't work try this:

$path = $_SERVER['DOCUMENT_ROOT'];
chdir($path."/drupal");
define('DRUPAL_ROOT', getcwd()); //the most important line
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);