How to access Drupal functions and sesions in a stand alone PHP script

If you want to access Drupal functions and sessions in your stand alone PHP scripts which is present any where in your project directory then how you will do this?

Let say you are going to create one websevices in drupal thats mean you have to create one PHP stand alone file then how you will access the Drupal functions?

First of all I am clearing this that this solution is for Drupal 7, not sure this will work in Drupal 6 or not, as I have not tested this in Drupal 6 environment.

Below are the code you have to write in you PHP stand alone file.

$path = getcwd();
$pos = strpos($path, 'sites');
$path = substr($path, 0, $pos);
$path = explode('\\', $path);

$length = sizeof($path);
unset($path[$length - 1]);
$path = implode('/', $path);

// Get the base path
define('DRUPAL_ROOT', $path);

//Include the bootstrap file for using the DRUPLA function in our file
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Now you can access any function of Drupal 7 in this stand alone PHP file :)

3 thoughts on “How to access Drupal functions and sesions in a stand alone PHP script

  1. I’m not sure where you are getting your info, but great topic. I needs to spend some time learning more or understanding more. Thanks for magnificent info I was looking for this info for my mission.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>