I have read this post.
Drupal is installed in my local machine and works fine. I have created a static page inside a directory in the drupal installation.
Like http://localhost/usertest/userts.php
If the page moved to root directory it works but when I move the page to usertest or any other directory it is not working.
Directory structure :
root – drupal installed directory containing all the drupal files including includes, modules, sites etc.
usertest – sub directory of root.
Code :
What my userts.php page contains is :
<?php
$currdir=getcwd();
chdir($_SERVER['DOCUMENT_ROOT']);
require_once("./includes/bootstrap.inc");
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
global $user;
chdir($currdir);
?>
<p>USER VAR :</p>
<?php print_r( $user ); ?>
OUTPUT :
The out put is given as anonymous user though I logged in :
USER VAR :
stdClass Object ( [uid] => 0 [hostname] => 127.0.0.1 [roles] => Array ( [1] => anonymous user ) [session] => [cache] => 0 )
But if I remove chdir part and move the file to root directory and access it
like http://localhost/userts.php then it gives me the current user object output.
I could not figure out what I have missed here. Can anyone help on this ?
You need to define
DRUPAL_ROOTEdit://
Having quickly been playing with this myself, the session won’t load your user property properly because the change in
$base_urlYou could fix this by using this code, before you initialise the DRUPAL_BOOTSTRAP