Loading bootstrap.inc in external PHP file in a subdirectory I'm trying to check if there is a user logged into drupal in a PHP script that resides within a subdirectory of the drupal root. I know that there can be issues with calling the bootstrap anywhere apart from in the drupal root, so I've created a drupal_bridge.inc.php file inside the root containing the following code, which I then call in the PHP script using include.

&lt;?php 

define("DRUPAL_ROOT",     "/var/www/vhosts/mysite.com/httpdocs/");

$current_wd = getcwd();

chdir(DRUPAL_ROOT);

print getcwd();

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';


global $base_url;

$base_url = (array_key_exists('HTTPS', $_SERVER) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'];

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

chdir($current_wd);

global $user;

if ($user-&gt;uid) {
    print "Logged in";
} else {
   print "Logged out";
}

echo 'INCLUDED';

?&gt;


However, when I visit the PHP script in the browser it says I am logged out. Strangely though if I visit the drupal_bridge.inc.php file directly it can access the user information and it says that I am logged in. 

I have set $cookie_domain = .mysite.com in the settings file as well. I have password protected the directory containing the PHP script but I didn't think that made a difference at this level.

Any ideas?

Also, I have looked into turning this in a module but it is not really practical so I would appreciate it if you did not advise doing so.

UPDATE: I just did a print_r($GLOBALS); to see if I could find out what was actually available and I found the following errors, if that helps.
http://pastebin.com/YtHPGD75 (too long to post here)
The bare minimum required is:

define('DRUPAL_ROOT', '/var/www/vhosts/mysite.com/httpdocs/');
$_SERVER['HTTP_HOST'] = 'mysite.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);


If you don't want to fully bootstrap and only get the session, see the technique defined in Getting the current user without bootstrapping to DRUPAL_BOOTSTRAP_SESSION