View Full Version : Controlling access to external pages via vB credentials
dontpanic
02-19-2004, 06:13 PM
In vB 2.x I was able to use this code to control access to a page based on member group.<?php
error_reporting(7);
require('./global.php');
if ($bbuserinfo[usergroupid]=="1" or $bbuserinfo[usergroupid]=="3" or $bbuserinfo[usergroupid]=="0") {
eval("dooutput(\"".gettemplate('newsletter_subscribe_error')."\");");
}else{
eval("dooutput(\"".gettemplate('newsletter_subscribe')."\");");
}
exit;
?>I'm missing something when I try to convert it over....can someone please show me what this should look like to accomplish the same basic goal in vB 3.x?
Thanks!
assassingod
02-19-2004, 06:19 PM
Most of the variables and functions have changed in vB3 now, you should use something like
<?php
error_reporting(E_ALL & ~E_NOTICE);
require("./global.php");
$globaltemplates = array(
'newsletter_subscribe_error',
'newsletter_subscribe'
);
if(in_array($bbuserinfo['usergroupid'], array(0,1,3)))
{
eval('print_output("' . fetch_template('newsletter_subscribe_error') . '");');
}
else
{
eval('print_output("' . fetch_template('newsletter_subscribe') . '");');
}
?>
dontpanic
02-19-2004, 06:25 PM
OK, lemme try it out and I'll let you know how it went.
Thanks! :)
Zachery
02-19-2004, 06:25 PM
Should that be require_once ? :P
assassingod
02-19-2004, 06:27 PM
It doesn't have to but yes it can be.
dontpanic
02-19-2004, 06:44 PM
OK, works like a charm. I just dropped the correct code into a pre-existing page as you can see:<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'index');
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// pre-cache templates used by all actions
$globaltemplates = array(
'navbar',
'flash1',
'STANDARD_ERROR'
);
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once('./includes/functions_bigthree.php');
require_once('./includes/functions_forumlist.php');
// ### ALL DONE! SPIT OUT THE HTML AND LET'S GET OUTA HERE... ###
if(in_array($bbuserinfo['usergroupid'], array(6,11)))
{
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('flash1') . '");');
}
else
{
eval('print_output("' . fetch_template('STANDARD_ERROR') . '");');
}
?>If we are evaluating members who's primary user group is 6 or 11, it works great. That's administrators and a subscription group. However, if you are a member of the subscription group (11) and its a secondary group, it does not work correctly, you fall into the else statement. Thoughts?
assassingod
02-19-2004, 06:54 PM
Can't think why that's happening. Also, theres unnessacary code in that script
(Unless you need to require bigthree.php and forumlist.php)
dontpanic
02-19-2004, 06:59 PM
Yeah, I got rid of those two requires...I didn't notice them at first. The only solution I see is to have the subscription event change the primary user group from 1 to 11 instead of configuring it as a secondary user group....I can't see that this would be a problem, but I'm not sure.
assassingod
02-19-2004, 07:00 PM
What I would do is use 1 print_output and use the fetch_templates in each if section.
E.g;
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'pagename');
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// pre-cache templates used by all actions
$globaltemplates = array(
'navbar',
'flash1',
'STANDARD_ERROR'
);
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// ### ALL DONE! SPIT OUT THE HTML AND LET'S GET OUTA HERE... ###
if(in_array($bbuserinfo['usergroupid'], array(6,11)))
{
eval('$var1 = "' . fetch_template('template-for-usergroupids-specified') . '";');
}
else
{
eval('$var1 = "' . fetch_template('template-for-everyone-else') . '";');
}
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('main-template-here') . '");');
?>
Then use $var1 in the main-template-here template.
dontpanic
02-19-2004, 07:04 PM
OK, so what would that look like? I'm not quite seeing it...been a long day. :ermm:
assassingod
02-19-2004, 07:04 PM
^Recheck my post:)
dontpanic
02-19-2004, 07:10 PM
OK...I see it. Basically just a cleaner way of doing what I had?
As well, do you know what the correct template to call for the login form is?
assassingod
02-19-2004, 07:11 PM
Yeah, aslo there's an EVEN cleaner away of doing it with vB3 conditionals.
dontpanic
02-19-2004, 07:12 PM
Well, I'm cool with conditionals. I wonder if it work to solve the secondary user group issue...I'll have to try it. What value would I be looking for? Same as in the code I've got now?
assassingod
02-19-2004, 07:15 PM
Yeah, you'd use in the template:
<if condition="in_array($bbuserinfo['usergroupid'], array(6,11))">
the main stuff here
</if>
Or if that doesnt work:
<if condition="in_array($bbuserinfo['usergroupid'], array(6,11))">
the main stuff here
<else />
everything else
</if>
dontpanic
02-19-2004, 07:17 PM
OK, cool. I want the else to make them go to the login form though...where can I find that bit of code?
assassingod
02-19-2004, 07:20 PM
OK, cool. I want the else to make them go to the login form though...where can I find that bit of code?
STANDARD_ERROR template
dontpanic
02-19-2004, 07:53 PM
OK, so far so good. It works nicely.
I wonder if vB 3.x uses a different variable for secondary user group membership...
dontpanic
02-19-2004, 07:59 PM
And the answer to that question is YES!
Secondary user groups: membergroupids
assassingod
02-19-2004, 08:00 PM
Ahh , ok:)
dontpanic
02-19-2004, 08:12 PM
So, in reality, since I needed to control access based on the secondary user group of 11, I used this code to do it:<if condition="in_array($bbuserinfo['membergroupids'], array(11))">As long as a member is a member of group 11 as a secondary group, then they can see the page.
Thanks!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.