---
title: "Is there a Drupal function to check if the user is logged in?"
date: "2025-02-05T23:14:33+00:00"
summary:
image:
type: "article"
url: "/acquia-cloud-platform/help/92876-there-drupal-function-check-if-user-logged"
id: "db7c46a9-542d-498a-8571-76b1828af33f"
---

Yes, and the function to use depends on the version of Drupal that you're using with your website.

Drupal 6 and 7
--------------

The function to use is called `user_is_logged_in`, and it can determine if a given user is logged in. For complete documentation on the function, click the appropriate link from the following, based on your Drupal version:

*   **[Drupal 7 `user_is_logged_in`](http://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_is_logged_in/7)** function information from drupal.org
*   **[Drupal 6 `user_is_logged_in`](http://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_is_logged_in/6)** function information from drupal.org

The function is a boolean that returns **TRUE** if the user is logged in, and **FALSE** if the user is anonymous.

Note

Functions and their usage can change between Drupal versions.

Drupal 8
--------

There are a couple of methods that you can use in Drupal 8 to make this check:

*   Use the [`isAuthenticated()`](https://api.drupal.org/api/drupal/8/search/isAuthenticated) method on the user. For example, use the following code to determine the state of the current user:
    
        $logged_in = \Drupal::currentUser()->isAuthenticated();
    
*   Use [`isAnonymous()`](https://api.drupal.org/api/drupal/8/search/isAnonymous) to determine if the user is anonymous:
    
        \Drupal::currentUser()->isAnonymous();