0

I'm migrating my website to a new server and I'm facing a problem since then. Files are identical, so I have no clue.

I want to access the global user variable in a subfolder, which is a custom php site. Here is how I try to access it:

<?php
// require global settings
require_once 'globals.php';
require_once BACKEND_CORE_PATH . '/spoon/spoon.php';

// The domain to be used for session cookies
$cookie_domain = DOMAIN_COOKIE;
$base_url = DRUPAL_URL;

// require the bootstrap include
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

// Load Drupal
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// get the Drupal user
global $user;

All includes are working fine, but when i dump the $user variable I get the following (while I'm logged in). At least I guess all includes are working since I got no errors.

object(stdClass)#14 (6) {
  ["uid"]=>
  int(0)
  ["hostname"]=>
  string(13) "XX.XXX.XXX.XX"
  ["roles"]=>
  array(1) {
    [1]=>
    string(14) "anonymous user"
  }
  ["cache"]=>
  int(0)
  ["session"]=>
  string(0) ""
  ["timestamp"]=>
  string(10) "1535128081"
}

Note: The XXX in the hostname is edited by me. Someone has a clue why it isn't working?

If I dump $GLOBALS, i see all drupal info, but only users says i'm not logged in..

PS: This is Drupal 7

  • I'm guessing that while you are logged in within Drupal, you are not logged in from your external script. You'll have to figure out how to log in programatically with the script you are writing. – Jaypan Aug 24 '18 at 21:48
  • You might want to try rebuilding permissions. – Sanjok Gurung Sep 3 '18 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.