PDA

View Full Version : Allowing only certain users to visit script


BamaStangGuy
11-27-2007, 11:07 AM
I have a new product I am creating and one of the setting options allows you to add userids, seperated by a comma, that you want to have access to the script.

How can I take those userids and compare them to the current users id trying to access the script to make sure that they match?

Right now this isn't working:

$aids = explode(',',$vbulletin->options['users_allowed']);
if ((!$vbulletin->options['vbincome_enabled']) OR in_array($bbuserinfo[userid], $aids))
{
print_no_permission();
}

What is the correct way to do this?

jwocky
11-27-2007, 05:22 PM
Do you want to check the user who is currently viewing the script and decide if that user is allowed to view the script?

Opserty
11-27-2007, 05:24 PM
Use $vbulletin->userinfo['userid'] instead of $bbuserinfo[userid]

I think you need to add a not (!) before the in_array().

BamaStangGuy
11-28-2007, 09:05 AM
Do you want to check the user who is currently viewing the script and decide if that user is allowed to view the script?
Yes

Use $vbulletin->userinfo['userid'] instead of $bbuserinfo[userid]

I think you need to add a not (!) before the in_array().

Thanks I'll give that a go.

Dean C
11-28-2007, 09:39 AM
What!? You mean vBSEO doesn't do all of this for you and more :rolleyes: ;)


$aids = explode(',',$vbulletin->options['users_allowed']);
if (!empty($vbulletin->options['vbincome_enabled']) OR !in_array($bbuserinfo[userid], $aids))
{
print_no_permission();
}


Checking for !($value) will match false, as the poster below me pointed out.

Opserty
11-28-2007, 10:58 AM
Are you sure you can use isset there? Because even if the option is set to say, false it will still read that the variable is set, won't it?

Dean C
11-28-2007, 11:02 AM
Are you sure you can use isset there? Because even if the option is set to say, false it will still read that the variable is set, won't it?

Woopsie, too used to checking to see if array keys exist :)