0

There are a number of properties on the global $user object https://api.drupal.org/api/drupal/developer%21globals.php/global/user/7

But I can't figure out how to see if a logged in user has ever previously logged in, or if this is his/her first session. When logged in, the $user->access, $user->login, $user->timestamp values all seem to point of the current session.

I can set a cookie and check for that cookie myself. But I suspect I'm just missing something Drupal already has ?

5
  • 2
    $user->access should work for you. drupal.stackexchange.com/questions/34397/…
    – arpitr
    Nov 10, 2015 at 16:32
  • good find @arpitr this question could qualify as a duplicate of 34397 Nov 10, 2015 at 20:37
  • $user->access seems set to the current login here, not the previous. perhaps that's not true on hook_user_login, but it seems to be so in subsequent requests ?
    – commonpike
    Nov 10, 2015 at 20:49
  • in the subsequent requests it will set to timestamp when accessed, but not will be 0
    – arpitr
    Nov 12, 2015 at 4:23
  • exactly. so its not a duplicate of 34397
    – commonpike
    Nov 13, 2015 at 10:55

1 Answer 1

1

A cookie would work. Another way is to add a field to the user entity that you can check that field first to see if it's empty, and then modify it with a Rule, triggered by the log in action

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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