View Full Version : <if> conditional
bigdog829
03-10-2007, 10:32 PM
Is there a way I could write an <if> conditional that I could include multiple i.p. addys instead of say a certain usergroup.
I don't understand nothing from your request.
A code example will help us to understand what exacly you are trying to achieve.
Post one and I will help you. :)
HMBeaty
03-10-2007, 11:49 PM
I would assume bigdog829 is looking for something like this:
<if condition="is_member_of($bbuserinfo, 5,6,7)">
</if>
but instead of using $bbuserinfo, 5,6,7.........use an IP address.
Correct me if I am wrong
bigdog829
03-10-2007, 11:57 PM
I would assume bigdog829 is looking for something like this:
<if condition="is_member_of($bbuserinfo, 5,6,7)">
</if>
but instead of using $bbuserinfo, 5,6,7.........use an IP address.
Correct me if I am wrong
Exactly what Im loking for sorry if I didnt explain it well enough !
Thanks
If it's what Redlinemotorsports said, this is very easy.
Use this function:
/**
* Checks to see if the IP address of the visiting user is allowed and defines a conditional
*
* @param string String of allowed IP's
*/
function check_allowed_ip($iplist = '')
{
global $show;
if (empty($iplist))
{
return;
}
$show['allowedip'] = false;
$user_ipaddress = IPADDRESS . '.';
$addresses = preg_split('#\s+#', $iplist, -1, PREG_SPLIT_NO_EMPTY);
foreach ($addresses AS $allowed_ip)
{
if (strpos($allowed_ip, '*') === false AND $allowed_ip{strlen($allowed_ip) - 1} != '.')
{
$allowed_ip .= '.';
}
$allowed_ip_regex = str_replace('\*', '(.*)', preg_quote($allowed_ip, '#'));
if (preg_match('#^' . $allowed_ip_regex . '#U', $user_ipaddress))
{
$show['allowedip'] = true;
}
}
}
Function Usage
// separate allowed IP's by a space, you could define a vB option for that
$allowediplist = '127.0.0.* 127.1.1.53';
check_allowed_ip($allowediplist);
In your template, all you have to do is add this condition:
<if condition="$show['allowedip']">
... do your stuff for allowed users only ...
</if>
In other words, users who have an IP starting with 127.0.0.* or users with the exact IP 127.1.1.53 will be able to see your stuff.
Hope that helps.
BTW, this was not tested, it was done off my mind.
bigdog829
03-11-2007, 02:19 AM
Im not looking to allow certain ip's I actually want to redirect certain ones I figured a if conditional with a simple html redirect would do the trick.
Aha, so why you did not post this from the beginning then?
From your post:
Exactly what Im loking for sorry if I didnt explain it well enough !
If you found a solution, you should post it here, so others can benefit from your experience.
That what is all about at vb.org, sharing knowledge with other hackers.
bigdog829
03-11-2007, 05:06 PM
Aha, so why you did not post this from the beginning then?
From your post:
Exactly what Im loking for sorry if I didnt explain it well enough !
If you found a solution, you should post it here, so others can benefit from your experience.
That what is all about at vb.org, sharing knowledge with other hackers.
I didnt find a solution yet & I deff would post it here if I did.
JorgeX
03-11-2007, 11:50 PM
TECK, it's offtopic but can u explain step by step your script? i'm learning php and i want to absorb knoledge :p
Gray Matter
03-12-2007, 01:53 AM
Try:
<if condition="$bbuserinfo[ipaddress] == 'xxx.xxx.xxx.xxx'">
</if>
Hi JorgeX,
The function defines a boolean condition (true/false), based on the string you input.
Then, you simply use that condition into your templates.
You can use arbitrary IP values, as described in the above script comments.
The script has a failsafe feature. If for some reason you use something like:
$allowediplist = '';
check_allowed_ip($allowediplist);
the script will not execute any code. I made this thinking that someone might add a vbulletin option and leave it emply by default. In this way the function will not burden the server with un-needed executed code.
bigdog829
03-12-2007, 05:23 PM
Try:
<if condition="$bbuserinfo[ipaddress] == 'xxx.xxx.xxx.xxx'">
</if>
No that didnt work thanks for the effort any other ideas ?
You cannot do it with a simple conditional, you need to go the hacker way, that's why you are here at vb.org site. :)
Here, simple like Bonjour.
/**
* Checks to see if the IP address of the visiting user is allowed and performs a redirect
*
* @param string String of allowed IP's
*/
function check_allowed_ip($iplist = '')
{
global $vbulletin;
if (empty($iplist))
{
return;
}
$user_ipaddress = IPADDRESS . '.';
$addresses = preg_split('#\s+#', $iplist, -1, PREG_SPLIT_NO_EMPTY);
foreach ($addresses AS $allowed_ip)
{
if (strpos($allowed_ip, '*') === false AND $allowed_ip{strlen($allowed_ip) - 1} != '.')
{
$allowed_ip .= '.';
}
$allowed_ip_regex = str_replace('\*', '(.*)', preg_quote($allowed_ip, '#'));
// choose where you want to redirect the non-allowed member
$vbulletin->url = 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'];
if (preg_match('#^' . $allowed_ip_regex . '#U', $user_ipaddress))
{
// choose where you want to redirect the allowed member
$vbulletin->url = $vbulletin->options['forumhome'] . '.php?' . $vbulletin->session->vars['sessionurl'];
}
eval(print_standard_redirect('redirect_updatethank s'));
}
}
// separate allowed IP's by a space, you could define a vB option for that
$allowediplist = '127.0.0.* 127.1.1.53';
check_allowed_ip($allowediplist);
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.