I have a very simple external php script which will not return the userId. The script is posted below:

include_once "/includes/bootstrap.inc";
global $user;
$userId = $user->uid;
echo $userId;

This script returns an empty string, and I cannot figure out why. Any help would be appreciated.

Note: I have checked to make sure bootstrap.inc is located in the correct directory. I've made sure the directory is accessible. This should be an easy process, but for some reason I just can't return the userId of the currently logged in user..

  • Have you tried to var_dump($user)? And what makes you sure your external script shares session with genuine Drupal site? – Mołot Jul 10 '14 at 9:32
  • var_dump($user) also returns an empty string.You might be right because I'm not even sure it shares the same session, I'm just trying solutions that were posted to previous yet similar questions here. – total_noob Jul 10 '14 at 10:02
  • It might help if you could tell us where your Drupal and your script are located. Just substitute actual domain with example.com if you don't want to make it public (it's about address / directory structure, not about where we can see your site, after all) – Mołot Jul 10 '14 at 10:15
  • Drupal is located locally at /www/drupal. The script is also located in the root directory, so it shouldn't have any problems accessing the includes folder. I'm almost certain this is not a permissions issue as the includes folder is set to full access. – total_noob Jul 10 '14 at 10:20
  • But $user should be NULL or Drupal user object. Empty string makes no sense. – Mołot Jul 10 '14 at 11:02

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.