Back to UserHelper class

Method getUserId

public static int
getUserId
(mixed $username)
Returns userid if a user exists
Parameters
  • string $username The username to search on.
Returns
  • int The user id or 0 if not found.
Since
  • 1.7.0
Class: UserHelper
Project: Joomla

Method getUserId - Source code

/**
 * Returns userid if a user exists
 *
 * @param   string  $username  The username to search on.
 *
 * @return  integer  The user id or 0 if not found.
 *
 * @since   1.7.0
 */
public static function getUserId($username)
{
    // Initialise some variables
    $db = Factory::getDbo();
    $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__users'))->where($db->quoteName('username') . ' = :username')->bind(':username', $username)->setLimit(1);
    $db->setQuery($query);
    return $db->loadResult();
}