A recent job had me doing this for a client where they wanted to add vBulletin if conditions to restrict access to info that was displayed on a non-vb page to certain usergroups. They also wanted to show certain links to members only and vice versa for unregistered users. I have a outlined a way to do this which should work for any non-vB pages below.
Edit: I’ve added information on calling a template from vBulletin like header.
Add the following 4 lines right at the top of every page that you want to have access control on your website.
It is ESSENTIAL that there is NO spaces or anything else before these lines.
Note that pages MUST be .php extension NOT .html
Note that you will have to modify the path in lines 2 and 3 (in bold) to suit your site before you upload.<?php
$curdir = getcwd ();
chdir(’/path/to/your/forums‘);
require_once(’/path/to/your/forums/global.php‘);
chdir ($curdir);
?>
Once you have added the top code and filled in the correct paths you can use conditionals to restrict or display content dependent on numerous things.
First Use
Show a link to people who are not logged in i.e register button. For example<?php
if ($vbulletin->userinfo['userid'] <1) { echo’link code goes here‘; }
?>Second Use
Another use is to display different content to users depending on if they are logged in or not. For example<?php
If ($vbulletin->userinfo['userid']!=0)
{
echo ‘Your logged in so we can display this’;
} else {
echo ‘Your not logged in so we display this’;
}
?>Third Use
If you want to restrict certain content to a usergroup you can use the following way. In the example the content is only visible to people who are in usergroup 5.<?php
if ($vbulletin->userinfo['usergroupid'] == ‘5‘ )
{
echo ‘This is only visible to people in usergroup 5′;}
?>You can take this further and restrict content to multiple usergroups using the following code . The example restricts content to usergroups 6, 7, 2 and 5.
<?php
if (is_member_of($vbulletin->userinfo, 6, 7, 2, 5)) {
echo ‘html code in between these two dashes’;
}
?>Fourth Use
You can further enhance these conditions using the else command shown below. All you need to do is add the below code before the php close tag ?>
else {
echo ‘You do not have permission for this page’; }For example:
<?php
if (is_member_of($vbulletin->userinfo, 6, 7, 2, 5)) {
echo ‘html code in between these two dashes’;
} else {
echo ‘You do not have permission for this page’; }
?>Adding a vBulletin template
In some cases you may want call templates directly from vBulletin including the functionality that is used in the template. Remember you still need to add the path code mentioned at the start.Add the following code to where you want to add your chosen template. You can include either one or multiple templates.
<?php
echo $header;
echo $navbar;
echo $status;
?>
If you have any questions feel free to leave them in comments. Ive tried this in cms like wordpress and works great.
Posted on July 11th, 2008 by Peter
Filed under: vBulletin | No Comments »
