Here is what I'm doing in an external script:

chdir('./../');
require_once "./includes/bootstrap.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); 
global $user;
echo $user->uid;

What am I doing wrong? It always returns 0 as the uid. I even tried doing DRUPAL_BOOTSTRAP_FULL.

Any ideas?

Comments

cog.rusty’s picture

Set $cookie_domain='example.com'; explicitly in your settings.php file.

ironj221’s picture

Thanks, I'll give that a try.

By any chance does Drupal keep the UID in a cookie so that I don't even have to load the environment?

cog.rusty’s picture

No, it doesn't, just a long session ID string.

sivaji_ganesh_jojodae’s picture

$cookie_domain trick works like a charm.

cog.rusty’s picture

By the way, since Drupal 6.17 things have changed and that should be $cookie_domain='.example.com'; with a front dot. (That works too in older versions.)