View Full Version : i.p. Banning
prideBMX
06-14-03, 06:46 PM
hey does anyone know where to get a script to ban someone from entering your site with there i.p.? i've looked all over for somthing it but cant find anything :confused: thanks
SilkySmooth
06-14-03, 06:59 PM
Hi,
IP Banning is not the most effective solution in the world because through certain connections and proxies the IP is changed multiple times. Not to mention they can be faked, but non the less the code is easy.
If we are talking about one specific IP number then something like this will do:
<?php
if ($_SERVER['REMOTE_ADDR']=="123.123.123.123")
{
echo "Your banned";
exit;
}
?>
If you want to block multiple IP's say less than 50 then you would use something like:
<?php
$BannedIPs=array("123.123.123.123","122.122.122.122","111....");
if (in_array($_SERVER['REMOTE_ADDR'],$BannedIPs))
{
echo "Your banned";
exit;
}
?>
Or if we are talking about IP Blocks then you would need a regular expression, something along the lines of:
<?php
if (ereg("^123.123.([0-9]{1,3}).([0-9]{1,3})$", $_SERVER['REMOTE_ADDR']))
{
echo "Your banned";
exit;
}
?>
If you are banning individual IP's above 50 then you will need some form of database driven solution for speed.
HTH
!!! HotCGIScripts !!!
06-14-03, 06:59 PM
You could ban you unwanted guests using .htaccess
deny from 127.1.2.3
or
deny from 127.1.2. to ban net
good luck.
or you could null route them in your routing table. just thought i would add that little tidbit.
amailer
06-15-03, 09:49 PM
thing with using those script[s] that SilkySmooth showed us, is that you have to put it on every page.... .htaccess is better
Darkness22k
06-15-03, 11:03 PM
Yes, but you could just put in it a file then use "include("file.php");" on every page.
thats still an extra line of code you don't need. .htaccess would do just fine, plus it will stop all access, not just php scripts.
SilkySmooth
06-16-03, 01:31 AM
Not all servers run Apache though ;)
yes but most servers copy Apache's .htaccess files, .htaccess is the way to go its very easy to use and theres no stuffing around with includes and time wasting to execute some code to ban one person.
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.