Other languages:
čeština 18% • ‎English 100% • ‎español 100% • ‎français 29%

Returns a reference to the global user object, only creating it if it doesn't already exist. The object returned will be of type JUser.


object JUser getUser( $id )


Argument Data type Description Default
$id integer The user to load. If the argument is omitted or is null then the current user will loaded. null

Example 1

In this example, some information about the current logged in user is displayed, but only when the user is actually logged in.

$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 />';

Example 2

In this example, a check is made to determine if the current user has edit permission on content. For more information on permissions see JAuthorization. See also JFactory->getACL.

$user = JFactory::getUser();
if ($user->authorise( 'com_content', 'edit', 'content', 'all' )) {
  echo 'Editing permitted.';
} else {
  echo 'Editing not permitted.';

See also