Click to See Complete Forum and Search --> : URGENT! Bann?


Jonathan
08-16-2003, 09:38 PM
How do you ban someone from your site using their IP addresS?

pyro
08-16-2003, 09:46 PM
in PHP:

untested code
<?PHP
if ($_SERVER["REMOTE_ADDR"] == 000.000.000.000) {
header ("Location:http://www.yourdomain.com/banned.php");
}
?>That code must go at the very top of your page, before any content is printed.

Jonathan
08-16-2003, 09:48 PM
If I add more do I do this?


<?PHP
if ($_SERVER["REMOTE_ADDR"] == 000.000.000.000 || $_SERVER["REMOTE_ADDR"]== 000.000.000.001) {
header ("Location:http://www.yourdomain.com/banned.php");
}
?>


And thanks for that speedy reply!

pyro
08-16-2003, 09:51 PM
Yep, looks good (except for the header, which I know is from the forums...)

Jonathan
08-16-2003, 09:53 PM
It has to be on the same line right?

pyro
08-16-2003, 09:56 PM
The if statement? Yes...

Jonathan
08-16-2003, 09:57 PM
Is this okay?

[php]
<?PHP
if ($_SERVER["REMOTE_ADDR"] == 222.222.222.222) {
header ("Location:banned.html");
}
?>

pyro
08-16-2003, 10:02 PM
I just thought of something. You'd better enclose the IP's you are banning in quotes. Also, for the header, you can use a relative path, but you are supposed to use an absolute path.

PeOfEo
08-17-2003, 12:03 AM
IP addresses change though. So you might ant to ban a range of ip addresses to keep them out for good.

Jonathan
08-17-2003, 01:24 AM
how do you bann a range of ip addresses?>

PeOfEo
08-17-2003, 12:41 PM
I dont know what it would look like in php but it would be something like
if remoteaddr < someip and > someip then redirect. It would just be a simple if statment with less than and greater then in it.

pyro
08-17-2003, 12:47 PM
To take all IPs from 000.000.000.000 to 000.000.000.999 use if ($ip >= "000.000.000.000" && $ip <= "000.000.000.999") Note that by banning an IP block, you will potentially ban a large number of users...

PeOfEo
08-17-2003, 12:57 PM
But by not banning a block the user simply has to reconnect on another ip to come back. The best solution would be a timed system where an ip block is banned for several hours then is lifted, but it would require a data base that sotres the ip and I am guessing some xml or a system that logs the time then on page load it can be checked and unbanned by another user. But it would be very very complicated and involve xml with a server sid elanguage most likely.

Robert Wellock
08-18-2003, 10:45 AM
It may have been easier to use .htaccess to ban the IP numbers.

Daot Lagorille
08-18-2003, 02:34 PM
As all my "rap artist" friends say:

"This **** is tight!"

Nice bit o' the ol' "php" code there.

PeOfEo
08-18-2003, 03:52 PM
o...k

pyro
08-18-2003, 04:28 PM
Lol... glad you like it... :D