6.x user.module user_is_logged_in()
7.x user.module user_is_logged_in()

Determines if the current user is logged in.

Return value

bool TRUE if the user is logged in, FALSE if the user is anonymous.

1 call to user_is_logged_in()
user_menu_title in modules/user/user.module
Menu item title callback for the 'user' path.
2 string references to 'user_is_logged_in'
session_test_menu in modules/simpletest/tests/session_test.module
Implements hook_menu().
user_menu in modules/user/user.module
Implements hook_menu().


modules/user/user.module, line 1575
Enables the user registration and login system.


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


zhilevan’s picture

this is good solution when we want check the menu only for users login , can use this in access callback menu property like this

$items['custmomenu'] => array(
      'title' => 'yourtitle',
      'page callback' => 'yourcallback function' ,
      'access callback' = > 'user_is_logged_in',

the usefull and short solution

leex’s picture

KeyboardCowboy’s picture

That function does not do what its name would imply. It can return false positives for admin users. See issue https://www.drupal.org/node/327230.

If you truly want to use an API call to check if the current user is authenticated or not, use user_is_logged_in() and !user_is_logged_in()

marc.groth’s picture

In Drupal 8 you use the isAuthenticated() method on the User. For the current user:

$user = \Drupal::currentUser()->isAuthenticated();

marc.groth’s picture

Of course the $user variable should probably be named something more apt, such as $logged_in.

Alternatively you can check if the user is anonymous like this:


saradaprasad17’s picture

need to check if the user has logged in or not