Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ban Script
#1
Here is a very effective IP Banning script.
Add the ips, one ip per line in ip.txt, u can even use * as a wildcard.

Just include the ban.php to all your web pages then you can add ips to the ips.txt file. The probelm is if you have a large ban file it can make your website slow. I did not make this.

ip.txt
Code:
66.249.73.*
192.168.1.*

ban.php
Code:
<?php

/**
* @author optiplex
* @copyright 2008
* coded by optiplex, have fun ;)
*/

error_reporting(0);

if ($handle = fopen("ip.txt", "r+")) {

    $ip = explode("
", fread($handle, filesize("ip.txt")));
    for ($i = 0; $i < count($ip); $i++) {
        $ip[$i] = str_replace("*", "(.*)", $ip[$i]);

        if (ereg($ip[$i], $_SERVER['REMOTE_ADDR'])) {
            header("Location: http://google.com/");
        }
    }

    fclose($handle);
}

?>
Reply
#2
What appears when the banned person gets in the banned page? Can I customize that?
Reply
#3
at the moment it redirects to google.com

"header("Location: http://google.com/");"

but you could redirect to a custom ban.html or do " echo "Sorry you appear to be banned" "
Reply
#4
Great, thanks for this man.
Reply
#5
np Smile
Reply
#6
Nice simple ban script. Good job. Smile
Reply
#7
You can improve it a bit by including $_SERVER['HTTP_X_FORWARD_FOR'] variable, if the user is trying to use a proxy which has been configured to allow this server variable Smile


So,
PHP Code:
if ($_SERVER['HTTP_X_FORWARD_FOR']) {
$ip_user $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$ip_user $_SERVER['REMOTE_ADDR'];


Thanks for sharing, it will be useful Smile
Reply
#8
(10-08-2009, 01:58 PM)brett7 Wrote: at the moment it redirects to google.com

"header("Location: http://google.com/");"

but you could redirect to a custom ban.html or do " echo "Sorry you appear to be banned" "

That would just add it to the start of the page, you'd have to die(); it to stop the actual page from loading.
[Completely Honest. Seriously.]

Protip: Anonymous Reputation Points are for Pussies
Reply
#9
I need help in this piece of code.

First of all,I prepare myself an index.php

Quote:<html>
<body>

<?php
include("bans.php");
?>

<p>
Welcome People !
</p>
</body>
</html>

Secondly,I prepared the ip.txt.I am running this script on Apache server running locally.Both of the IPs are pointing toward my machine.

Quote:127.0.0.1
192.168.1.5

Finally,I paste in this code bans.php,but I coundn't get this to work.

I still can access the site.

The message "Welcome people" still showing on my screen.

I am very new to PHP.

Anyone can guide me?

Thanks.
Reply
#10
^^
It works well for me, post your PHP code you did something wrong.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  php form script with upload script help andrewjs18 4 3,349 10-07-2010, 11:46 AM
Last Post: JMK940
  Auto Ban IP's & Host's zone 2 1,197 11-06-2009, 09:15 PM
Last Post: zone

Forum Jump:


Users browsing this thread: 3 Guest(s)