Get Joomla user group id using PHP

To get the user group id in Joomla 2.5.15, I completed the documentation in the Joomla Documentation here

My code is as follows:

$user = JFactory::getUser(); echo "<p>Your group id is {$user->gid}.</p>"; 

But this code causes an error: Note: Undefined property: JUser :: $ gid in Without group identifier at the output.

+7
php joomla
source share
3 answers

Try using this:

 $user = JFactory::getUser(); $groups = $user->get('groups'); foreach ($groups as $group) { echo '<p>Group = ' . $group . '</p>'; } 
+13
source share
 jimport( 'joomla.access.access' ); $groups = JAccess::getGroupsByUser($user_id, false); var_dump($groups); 
+1
source share

FROM DOCS

 $user = JFactory::getUser(99); echo "<p>Your usertype is {$user->usertype} which has a group id of {$user->gid}.</p>"; 
-one
source share

All Articles