Accessing the current user object

From Joomla! Documentation


For every request in Joomla!, there is one user. Information about this user is readily available through the Joomla! framework in the form of an object. To get this object for the current user, use the following member function of JFactory:

$user = JFactory::getUser();

Or, to get information about any other registered user you can call the function with a user 'id', e.g. for user '99';

$user = JFactory::getUser(99);

Getting a reference through getUser() ensures that only one user object is created during any one Joomla! request, saving on memory and processing time. Most of the information about the user is available through public member variables of the user object. This code displays the current user's name, email, user name and user type:

echo "<p>Your name is {$user->name}, your email is {$user->email}, and your username is {$user->username}</p>";

Note: Since version 1.6 Joomla has a flexible ACL system, which makes $user->usertype deprecated!

The usertype field in #__users will only contain values for users that have been migrated from Joomla 1.5, but for new created users the field will be empty.

Use $user->groups to retrieve an array with all the IDs that refer to the groups (from #__usergroups table) of a user.

Object Member Variables and Parameters

These are the relevant member variables automatically generated on a call to getUser():

  • id - The unique, numerical user id. Use this when referencing the user record in other database tables.
  • name - The name of the user. (e.g. Vint Cerf)
  • username - The login/screen name of the user. (e.g. shmuffin1979)
  • email - The email address of the user. (e.g.
  • password - The encrypted version of the user's password
  • password_clear - Set to the user's password only when it is being changed. Otherwise, remains blank.
  • usertype - The role of the user within Joomla!. (Super Administrator, Editor, etc...) Has been deprecated since Joomla 1.6. Use $user->groups to retrieve an array with all the roles of a user.
  • groups - Set to the user's group ids.
  • block - Set to '1' when the user is set to 'blocked' in Joomla!.
  • registerDate - Set to the date when the user was first registered.
  • lastvisitDate - Set to the date the user last visited the site.
  • guest - If the user is not logged in, this variable will be set to '1'. The other variables will be unset or default values.
  • lastResetTime - Set to the last time the password was reset.
  • resetCount - Counts the number of password resets.

In addition to the member variables (which are stored in the database in columns), there are parameters for the user that hold preferences. To get one of these parameters, call the getParam() member function of the user object, passing in the name of the parameter you want along with a default value in case it is blank.

$user = JFactory::getUser();
$language = $user->getParam('language', 'the default');
echo "<p>Your language is set to {$language}.</p>";

Determining Status

Frequently, you will just want to make sure the user is logged in before continuing. The 'guest' property will be set to '1' when the current user is not logged in. When the user is authenticated, 'guest' will be set to '0'.

	$user = JFactory::getUser();
	if ($user->guest) {
		echo "<p>You must login to see the content. I want your email address.</p>";
	} else {
		echo "<p>You are logged in, you can see the content.</p>";


Not all users are given equal rights. For instance, a Super Administrator may be able to edit anyone's content, while a Publisher may only be able to edit their own. The authorise() member function can be used to determine if the current user has permission to do a certain task. The first parameter is used to identify which task we wish to check being allowed. The second represents the component we wish to retrieve the ACL information from.

	$user = JFactory::getUser();
	if ($user->authorise('core.edit', 'com_content'))
		echo "<p>You may edit all content.</p>";
		echo "<p>You may not edit all content.</p>";
	if ($user->authorise('core.edit.own', 'com_content'))
		echo "<p>You may edit your own content.</p>";
		echo "<p>You may not edit your own content.</p>";


Information about the current user is readily available in any part of your Joomla! extension. You need only fetch the object and access the member variables. You can authorise the user against the core permissions set, or create your own to suit your needs.

External Links

Joomla 3.9 API reference