8.5.x user.module user_load($uid, $reset = FALSE)
8.0.x user.module user_load($uid, $reset = FALSE)
8.1.x user.module user_load($uid, $reset = FALSE)
8.2.x user.module user_load($uid, $reset = FALSE)
8.3.x user.module user_load($uid, $reset = FALSE)
8.4.x user.module user_load($uid, $reset = FALSE)
8.6.x user.module user_load($uid, $reset = FALSE)
4.6.x user.module user_load($array = array())
4.7.x user.module user_load($array = array())
5.x user.module user_load($array = array())
6.x user.module user_load($user_info = array())
7.x user.module user_load($uid, $reset = FALSE)

Fetch a user object.


$user_info: Information about the user to load, consisting of one of the following:

  • An associative array whose keys are fields in the {users} table (such as uid, name, pass, mail, status) and whose values are the field's value.
  • A numeric user ID.

Return value

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

17 calls to user_load()
comment_form_add_preview in modules/comment/comment.module
Form builder; Generate and validate a comment preview form.
install_configure_form_submit in ./install.php
Form API submit for the site configuration form.
profile_browse in modules/profile/profile.pages.inc
Menu callback; display a list of user information.
system_send_email_action in modules/system/system.module
Implementation of a configurable Drupal action. Sends an email.
user_authenticate in modules/user/user.module
Try to log in the user locally.

... See full list


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


function user_load($user_info = array()) {

  // Dynamically compose a SQL query:
  $query = array();
  $params = array();
  if (is_numeric($user_info)) {
    $user_info = array(
      'uid' => $user_info,
  elseif (!is_array($user_info)) {
    return FALSE;
  foreach ($user_info as $key => $value) {
    if ($key == 'uid' || $key == 'status') {
      $query[] = "{$key} = %d";
      $params[] = $value;
    else {
      if ($key == 'pass') {
        $query[] = "pass = '%s'";
        $params[] = md5($value);
      else {
        $query[] = "LOWER({$key}) = LOWER('%s')";
        $params[] = $value;
  $result = db_query('SELECT * FROM {users} u WHERE ' . implode(' AND ', $query), $params);
  if ($user = db_fetch_object($result)) {
    $user = drupal_unpack($user);
    $user->roles = array();
    if ($user->uid) {
      $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
    else {
      $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
    $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
    while ($role = db_fetch_object($result)) {
      $user->roles[$role->rid] = $role->name;
    user_module_invoke('load', $user_info, $user);
  else {
    $user = FALSE;
  return $user;


tmsimont’s picture

If using the default D6 profile module, you'll have to see this documentation http://drupal.org/node/873990 for profile_* values.

vparfaniuc’s picture

In Drupal 6, to get user by it username you can use this