6

Does the user_is_logged_in() method return TRUE if there is at least one user logged in? Or does it refer to the current session, and returns TRUE if the current user is logged in?

10

By looking at the Drupal API, you can see the function itself:

<?php
function user_is_logged_in() {
  return (bool) $GLOBALS['user']->uid;
}
?>

Which shows that it returns TRUE if the current session is a logged-in user, or FALSE if the current session is an anonymous user.

4

It refers to the current session.

2

The function checks that the user who is viewing the page is not the anonymous user, not that between all the users currently viewing the site there is a logged-in user. So, four users seeing the site will get a different result, basing on the fact each of them is logged-in or not.

  • I am no sure that I understand exactly what you said: It doesn't check if, apart the user currently viewing the page, there are other logged-in users. So if I have 2 users logged in the same time on different machines, it doesn't check for each? – Ek Kosmos May 10 '11 at 6:18
  • @Ek Kosmos No, it doesn't. If I am viewing a page, and I am logged in, then the function will return TRUE; if I am not logged in, then the function will return FALSE, even if there is another user that is logged in. – kiamlaluno May 10 '11 at 6:20
0

If you want to check which users or how many users are logged one option is to query the sessions table.

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.