[advanced search]
Next Live Event: NamePros Live Auction, May 23rd at 6PM EDT
Results from the May 8th live auction are here.
17 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 02-26-2008, 05:41 PM   · #1
Palyriot
NamePros Regular
 
Palyriot's Avatar
 
Name: Derek
Location: Seattle, Wa
Trader Rating: (14)
Join Date: Jul 2004
Posts: 590
NP$: 58.00 (Donate)
Palyriot is a jewel in the roughPalyriot is a jewel in the roughPalyriot is a jewel in the rough
Ban Script! Supports specific IPs and even ranges

This banning script should work for any range in any quartile of the IP. Even [0-255].[0-255].[0-255].[0-255] will work. With every $ip_range value you add, it will only get a very small fraction of a second slower. Running the script with 100 ip ranges took 0.00264000892639 seconds.

Have Fun!
PHP Code:
<?php

function checkban($ip, $banned_ip, $ip_ranges)
{
    
$ipquartiles = explode('.', $ip);
    if (
in_array($ip, $banned_ip))
    {
        return
true;
        
    }
    
    if (
$banned != true)
    {
        foreach(
$ip_ranges as $ip_range)
        {
            
$quartiles = explode('.', $ip_range);
            for (
$i = 0; $i <= 4; $i++)
            {
                if (
preg_match('/\[([0-9]+)\-([0-9]+)\]/', $quartiles[$i], $matches))
                {
                    
$start = $matches[1];
                    
$end = $matches[2];
                    if (
$ipquartiles[$i] < $start || $ipquartiles[$i] > $end)
                    {
                        return
false;
                    }
                    else
                    {
                        
$banned = true;
                    }
                }
                else
                {
                    if (
$quartiles[$i] != $ipquartiles[$i])
                    {
                        return
false;
                    }
                }
            }
        }
    }
    return
$banned;
}

$banned_ip = array();
$banned_ip[] = '204.96.148.3';
$banned_ip[] = '205.162.217.141';

$ip_ranges = array();
$ip_ranges[] = '[0-255].0.0.1';

$ip = $_SERVER['REMOTE_ADDR'];

$banned = checkban($ip, $banned_ip, $ip_ranges);

if (
$banned == true)
{
    echo
'banned!';
    
//header("location: http://www.yahoo.com");
}
else
{
   
// header("location: http://www.google.com");
   
echo 'not banned';
}

?>


Please register or log-in into NamePros to hide ads
Palyriot is offline   Reply With Quote
Reply

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Get Me Visits Join now! Get Me Visits
Advertise your business at NamePros
All times are GMT -7. The time now is 02:44 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0