View Full Version : Quick Permissions Question
manofphat
03-10-2007, 04:20 PM
Hello,
Currently this is the code I have in one of my plugins:
if (!in_array($vbulletin->userinfo['usergroupid'], array(5,6,12))) print_no_permission();
Currently, from my tests I can see that it's only checking the user's primary usergroup. How can I make it so it checks their additional usergroups as well?
Thank you!
Also, does vBulletin have some sort of IRC channel for quick questions like this?
if (!in_array($vbulletin->userinfo['usergroupid'], array(5, 6, 12)))
{
print_no_permission();
}
Login as usergroupid 12 and you will see that it works.
The way in_array() function works is simple: It checks through the array until an element matches, then it stops performing the rest of the check and returns a boolean result. That improves the code performance.
So if you are a member of usergroupid 6 and 12, it will not check for 12, since 6 is already true.
Still, is better to avoid those type of usergroup checks and use instead the vBulletin bitfield permissions.
For example, if I want to see if an user is an admin, I can use this:
$show['adminoption'] = (bool)($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel']);
if $show['adminoption']
{
// my action here...
}
I can use from now on anywhere in my script this condition, without processing several times the same check.
In global.php there are few boolean conditions already defined. I dont understand why no hacker use them in their code. They are there to be used, since they are already defined, so there is no need to perform extra code processing re-defining them again and again.
For example, $show['admincplink'] will check if you are an admin (uses deprecated code :().
$show['modcplink'] checks if you are either an admin or mod.
Take your time and look at the code, is pretty cool what you can find in there. :)
Those forums are made for posting, so others will be able to learn from threads, code examples, etc.
If you ask a question on an IRC channel, how do you think others will learn from your current problem?
Have fun with your vb hacking. :)
Princeton
03-11-2007, 12:20 PM
you can use
is_member_of($vbulletin->userinfo, 5,6,12) OR is_member_of($bbuserinfo, 5,6,12)
checks primary and secondary usergroup
manofphat
03-11-2007, 04:33 PM
Thanks to both of you! I have it working the way I want now!
:) :) :)
Inserting int's separated by comma's would mess with the 3rd function param, if I'm not wrong. If I check for one usergroupid, ya is ok, but for multiples, it will break the cache.
Pretty sure the function was ment to be used like:
is_member_of($bbuserinfo, array(5, 6, 12));
and not:
is_member_of($bbuserinfo, 5,6,12);
What do you guys think?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.