Support Forums

Full Version: Ban Script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
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);
}

?>
What appears when the banned person gets in the banned page? Can I customize that?
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" "
Great, thanks for this man.
np Smile
Nice simple ban script. Good job. Smile
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
(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.
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.
^^
It works well for me, post your PHP code you did something wrong.
Pages: 1 2 3