Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:45:38+00:00 2026-06-06T21:45:38+00:00

I have read this post. Drupal is installed in my local machine and works

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:45:41+00:00Added an answer on June 6, 2026 at 9:45 pm

    You need to define DRUPAL_ROOT

    define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']);
    require_once($_SERVER['DOCUMENT_ROOT'] . "/includes/bootstrap.inc");
    drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
    

    Edit://

    Having quickly been playing with this myself, the session won’t load your user property properly because the change in $base_url

    You could fix this by using this code, before you initialise the DRUPAL_BOOTSTRAP

    global $base_url;
    // Assuming your drupal installation lives in the DOCUMENT_ROOT
    //  -- Which yours does
    $base_url = (array_key_exists('HTTPS', $_SERVER) ? 'https://' : http://') . $_SERVER['HTTP_HOST'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read this post but I don't really understand the code... I have a
I have read this post: what happens to NSLog info when running on a
I have read this post and I can't meet my requirements. My Folder structure
I have read this helpful post : SharedPreferences.onSharedPreferenceChangeListener not being called consistently However I
I have already read this post , but I am not sure know to
I have read this post How can I use WCF with only basichttpbinding, SSL
hey guys, i have read This post, so what i got is JSON is
I have read through Scott Hanselman's post on this topic. I found another article
I have read this post and it doesn't answer my question. Stateless session bean
I have already read this post: Making TextView scrollable on Android without success. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.