PDA

View Full Version : Check persmissions using PHP?


CEMarijn
03-13-2009, 01:38 PM
Hi all,

I have a small question concerning custom php code. I want to include a link to a php file on my forum that everyone can see. This php script should then check if the user is logged in. If he is, he is redirected to the content. If not, he gets a message that he does not have permission.

I found the following code (this example should only work for admins), but that does not work.

<?php
if ($vbulletin->userinfo['usergroupid'] == '6' )
{
echo "Welcome to the premium section!";
} else {
echo "You do not have permission for this page"; }
?>

I outputted the usergroupid variable, but it is just empty. I am completely new to vbulletin, so this might be a very noobish question. But please help :) Thanks in advance!

Lynne
03-13-2009, 02:37 PM
You need to include global.php in the page in order to check for permissions. See this - [How-To] vBulletin API Basics: Creating Custom Pages & Misc. (https://vborg.vbsupport.ru/showthread.php?t=98009) Then you can check for usergroups by doing this:

if (is_member_of($vbulletin->userinfo, 5, 6, 7))
{
stuff only for members in groups 5, 6, and 7
}
else
{
print_no_permission();
}

CEMarijn
03-13-2009, 02:42 PM
Great, thanks for the quick reply, I'll get to it right away.

Dismounted
03-14-2009, 04:10 AM
Or you could just use:
if (!is_member_of($vbulletin->userinfo, 5, 6, 7))
{
print_no_permission();
}

// people that see this are authenticated
print_no_permission() will end the execution of a script. :)