How to get the logged in users id and username?

How do I get the ID and username of the currently logged in user?

Category: Development 4 years ago
Asked 4 years ago

To get the logged in users id: JFactory::getUser()->id;

To get the logged in users username: JFactory::getUser()->username;

Alternatively, you can set the user object into a variable for repeated use.

For example-

$user = JFactory::getUser();

Then access it anytime like this-

echo $user->name;

echo $user->email;

echo $user->id;


Explore the user object with a variable dump.


To see all the values contained in the user object.

If you want to use a users data that is not the currently logged in user,

simply put their id in as an arguement - 


Have Fun! 

Answered 2 years ago

Please register/login to answer this question.  Click here to login
Cron Job Starts