humm the in array is probably a better way of doing it, although i think your syntax has problems
PHP Code:<?php
$b[] = '0.0.0.1';
$b[] = '0.0.0.2';
$b[] = '0.0.0.3';
if(in_array($_SERVER['REMOTE_ADDR'], $b)){
die("You're banned.");
}
?>
Printable View
humm the in array is probably a better way of doing it, although i think your syntax has problems
PHP Code:<?php
$b[] = '0.0.0.1';
$b[] = '0.0.0.2';
$b[] = '0.0.0.3';
if(in_array($_SERVER['REMOTE_ADDR'], $b)){
die("You're banned.");
}
?>
I think my syntax is fine.
Edit: http://joshjh.pwp.blueyonder.co.uk/testing.gif (PHP/5.1.2)
This is how I'd do it.
Save this as Ban.php if you want.
Then on your index page, to check if the IP is banned... Add this code anywhere, preferably at the top.PHP Code:<?php
//Ban.php
$ip1 = 'xxx.xxx.xxx.xxx';
$ip2 = 'xxx.xxx.xxx.xxx';
$ip3 = 'xxx.xxx.xxx.xxx';
if($_SERVER['HTTP_X_FORWARDED_FOR'] == $ip1||$_SERVER['HTTP_X_FORWARDED_FOR'] == $ip2||$_SERVER['HTTP_X_FORWARDED_FOR'] == $ip3) {
echo("Sorry your banned.");
}
?>
PHP Code:<?php
include("ban.php");
?>
Thats actualy quite a good idea? Since you dont need to worry about whether the public or proxie Ips are not the one you banned since it checks all "/
Bravo
Nice tut there :)
Meh, you could use another way of doing it If you have a MySQL database and not alot of tables you can make)
PHP Code:<?php
include("configurationofmysqldatabasewithareallylongunneededname.php");
$dynamite = mysql_fetch_array(mysql_query("SELECT `ip` FROM `bannageness` ORDER BY `ip` DESC"));
$explosion = explode(";", $dynamite["ip"]);
for($num = 0; $num < count($explosion); $num++)
{
if($_SERVER["REMOTE_ADDR"] == "$explosion[$num]")
{
die("lol banned");
}
}
?>
right, i have this problem
my ban.php is in a directory such as
1/2/3/4/5/6/7/8/9/ban.php
and if i put this incluede on my homepage
<?php
include("ban.php");
?>
it only reads the same directory as the files in. and when i try to put in the full url such as
http://www.bonxy.co.uk/1/2/3/4/5/6/7/8/9/ban.php it comes up with loads of error lines. anyone know how i can get around this problem ????
+REP TO HELPERS!!!!!!
xxxxxx
Why not also set a banned cookie and a session and make it check for that so if it has either of the 3 then your banned...?
Can clear cookies, sessions, and change my IP very easily.
I don't really think there is a decent way of banning someone!