vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   <if> conditional (https://vborg.vbsupport.ru/showthread.php?t=141689)

bigdog829 03-10-2007 10:32 PM

<if> conditional
 
Is there a way I could write an <if> conditional that I could include multiple i.p. addys instead of say a certain usergroup.

TECK 03-10-2007 11:46 PM

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:
HTML Code:

<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

Quote:

Originally Posted by Redlinemotorsports (Post 1200538)
I would assume bigdog829 is looking for something like this:
HTML Code:

<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

TECK 03-11-2007 01:52 AM

If it's what Redlinemotorsports said, this is very easy.

Use this function:
PHP Code:

/**
* 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, -1PREG_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
PHP Code:

// 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:
Code:

<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.

TECK 03-11-2007 08:37 AM

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

Quote:

Originally Posted by TECK (Post 1200699)
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:

Code:

<if condition="$bbuserinfo[ipaddress] == 'xxx.xxx.xxx.xxx'">

</if>


TECK 03-12-2007 05:47 AM

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

Quote:

Originally Posted by Gray Matter (Post 1201290)
Try:

Code:

<if condition="$bbuserinfo[ipaddress] == 'xxx.xxx.xxx.xxx'">

</if>


No that didnt work thanks for the effort any other ideas ?

TECK 03-14-2007 12:35 AM

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.

Code:

/**
* 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_updatethanks'));
        }
}

// 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);



All times are GMT. The time now is 03:10 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01431 seconds
  • Memory Usage 1,764KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (2)bbcode_html_printable
  • (2)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (13)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete