0

I have this code:

global $user;

if (!$user->uid) {
  drupal_set_message("You must log in to view this content.");
  drupal_goto('node/153', array('query'=>drupal_get_destination()));
}

$user->uid evaluates correctly when logged in as admin and editor, but users that don't have admin or editor roles have NO UID. Immediately before and after this code resolves to false, I visit site-root/user, and sure enough, I'm logged in.

What setting causes this? I've used this code many times to see if a user is logged in, and I can't find any setting that would cause this behavior.

  • any clues from print_r($user)? – emc May 10 '13 at 23:28
  • try to clear cache. do you have any special drupal module installed that alters user object – Aboodred1 May 11 '13 at 0:03
  • 2
    That's impossibruuuu.. – AyeshK May 11 '13 at 5:34
2

Try using

global $user;

if(!$user->uid) {
  drupal_set_message("You must log in to view this content.");
  drupal_goto('node/153', array('query'=>drupal_get_destination()) );
}
  • My apologies, I do have global $user in my code, I forgot to state that in my question. I'll update it. – Indigenuity May 10 '13 at 23:16
  • Maybe you can try global $user; drupal_set_message(print_r($user, 1)); to see the content of the $user variable. – Gerardo May 10 '13 at 23:49
0

I'm not yet clear on all the reasons, but the Secure Pages module was causing all users that weren't selected to go on https to return as null. Even user_is_logged_in() was returning false.

Moving a user to https upon login returned these functions' behavior back to normal.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.