Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal - using boostrap to check logged in user outside of Drupal not working

I'm pulling my hair out trying to figure this one out. I can't get the Bootstrap to work properly when outside of the Drupal dir. It works fine if I run this code in the Drupal dir, but up one level doesn't work.

My Drupal path is /public_html/drupal/. The script I'm running is in /public_html.

$user is not returning the logged in user. I've made sure it's not a cross-domain issue (i.e. www.domain.com vs. domain.com).

chdir('/path/to/drupal');

include_once('./includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;

if ($user->uid) {
    print "Logged in";
} else {
   print "Logged out";
}
like image 223
Ian McIntyre Silber Avatar asked Jul 28 '10 22:07

Ian McIntyre Silber


1 Answers

If the user is not recognized by Drupal in your separate script, chances are high that it does not receive the proper session cookie. You should check the cookies set by your normal Drupal install and see if they get send to your script as well. If not, check the $cookie_domain variable in your Drupals settings.php - ususally it is commented out, but you might need to set it explicitly in your case.

like image 149
Henrik Opel Avatar answered Nov 14 '22 04:11

Henrik Opel