How to get the name, email or other user info in Joomla

First of all, before executing below code you should use Joomla’s Sourcerer plugin to execute PHP code.

In Joomla, you can easily request information about the current user with the following function of JFactory:
$user =& JFactory::getUser();

If you want to get information about a specific user you can call the function with a specific user id or username:

$user =& JFactory::getUser(463);
$user =& JFactory::getUser(george);

You can also get most of the information about the user through Member Variables of the user object like the user’s name or email:

$user_name = $user->name;
$user_email = $user->email;

Here is a list with the Member Variables of the user object:

id – The unique, numerical user id.
name – The name of the user.
username – The login/screen name of the user.
email – The email address of the user.
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…).
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.

If you want to know if the user is logged in, you can use the guest Member Variable:

$user =& JFactory::getUser();
if ($user->guest) {
     echo 'You are not logged in';
} else {
     echo 'You are logged in';



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s