Accessing user information (like name, username, registered date) is very simple process in Joomla. getUser function of JFactory class returns a reference to the global user object. You can use this information about the current user in any part of your Joomla! extension. You only need to fetch the object and access the member variables.

$user = JFactory::getUser();

if (!$user->guest) {
echo 'You are logged in as:<br />';
echo 'User name: ' . $user->username . '<br />';
echo 'Real name: ' . $user->name . '<br />';
echo 'User ID : ' . $user->id . '<br />';
}

Following member variables automatically generated on a call to getUser():

  1. guest
  2. id
  3. name
  4. username
  5. email
  6. password
  7. registerDate
  8. lastvisitDate
  9. lastResetTime
  10. resetCount
  11. block
  12. groups

How to check user is logged in or not

The guest property ($user->guest) is set to 1 when the current user is not logged in. When the user is authenticated, guest is is set to 0.

if ($user->guest) {
echo "<p>You must login to see the content. </p>";
} else {