Is it possible to query the user id or username of a logged in user in PHP/Joomla 3 and assign that to a variable? If so how?

Im trying to create user specific content. Specifically some graphs which are held in a location whos path includes reference to a directory with the same name as their site user id.

If I can pull their user id and assign that to a variable I can then create a path to their own specific content using the contents of the variable specific to them.


If I understand you correctly, you want to get the ID of the currently logged in user. In which case, you can simply use the following:

$id = JFactory::getUser()->id;
  • 2
    Keep in mind that guests will return an empty string when asking for an ID.
    – Chaosxmk
    Sep 27 '17 at 18:11
  • So cool, many thanks. Can this be dropped into an article for example? Sep 27 '17 at 18:20
  • 2
    @PaulaLivingstone - Yes, I can be put in an article, however you'll need to use a 3rd party extension to allow PHP inside an article. Sourcerer would be a good one to use.
    – Lodder
    Sep 27 '17 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.