I want to find out if a person is logged on or not what member of a group they are or if they are a superuser and use an if else to act accordingly.
However it returns the user id correctly using the user->id but returning the group id returns nothing, same with $user->aid returns nothing and $user->usertype returns nothing as well. Why is this and what do you think is the best way of going about this is?
$user =& JFactory::getUser();
if($user->guest)
{
echo "Guest" . $user->id;
}
else
{
echo "Group: ".$user->gid . " User " . $user->id;
//...//
}
However it returns the user id correctly using the user->id but returning the group id returns nothing, same with $user->aid returns nothing and $user->usertype returns nothing as well. Why is this and what do you think is the best way of going about this is?
Hi peterswa62,
Which version of Joomla! is this? The most recent Joomla! versions allow users to belong to more than one group so $user->gid doesn't work. I posted the current code here yesterday I think.
Bob
Which version of Joomla! is this? The most recent Joomla! versions allow users to belong to more than one group so $user->gid doesn't work. I posted the current code here yesterday I think.
Bob
Thanks. I'm using version 2.5. Tried also:-
if(in_array(8, $groups)){
echo 'only visible for super-users';
else if(in_array(2, $groups))
echo 'only visible for registered';
else
//
}
and:-
if(isset($user->groups['Administrator']) || isset($user->groups['Super Users']))
{
echo "I am admin or superuser.";
}
else if(isset($user->groups['Registered'])
{
echo "I am Registered.";
}
else
{
echo "Not member of any group.";
}
which I found using Google but they don't seem to work either.
if(in_array(8, $groups)){
echo 'only visible for super-users';
else if(in_array(2, $groups))
echo 'only visible for registered';
else
//
}
and:-
if(isset($user->groups['Administrator']) || isset($user->groups['Super Users']))
{
echo "I am admin or superuser.";
}
else if(isset($user->groups['Registered'])
{
echo "I am Registered.";
}
else
{
echo "Not member of any group.";
}
which I found using Google but they don't seem to work either.
This topic is locked and no more replies can be posted.