8.5.x user.module user_load_by_name($name)
8.0.x user.module user_load_by_name($name)
8.1.x user.module user_load_by_name($name)
8.2.x user.module user_load_by_name($name)
8.3.x user.module user_load_by_name($name)
8.4.x user.module user_load_by_name($name)
8.6.x user.module user_load_by_name($name)
7.x user.module user_load_by_name($name)

Fetch a user object by account name.


$name: String with the account's user name.

Return value

A fully-loaded $user object upon successful user load or FALSE if user cannot be loaded.

See also


12 calls to user_load_by_name()
comment_form_validate in modules/comment/comment.module
Validate comment form submissions.
comment_preview in modules/comment/comment.module
Generate a comment preview.
DBLogTestCase::doUser in modules/dblog/dblog.test
Generates and then verifies some user events.
LocaleUserCreationTest::testLocalUserCreation in modules/locale/locale.test
Functional test for language handling during user creation.
OpenIDRegistrationTestCase::testRegisterUserWithAXButNoSREG in modules/openid/openid.test
Test OpenID auto-registration with a provider that supplies AX information, but no SREG.

... See full list


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


function user_load_by_name($name) {
  $users = user_load_multiple(array(), array(
    'name' => $name,
  return reset($users);


aaronbauman’s picture

This function is a simple wrapper to DrupalEntityControllerInterface::load(), which statically caches results.

Calling this function more than once during a single pageload could return stale results.

usmanjutt84’s picture

Is this API works for only logged in user. If yes I need to load before login if exists. Any help