Support Forums
Ban Script - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: Ban Script (/showthread.php?tid=720)

Pages: 1 2 3


Ban Script - brett7 - 10-08-2009

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);
}

?>



RE: Ban Script - Headshot - 10-08-2009

What appears when the banned person gets in the banned page? Can I customize that?


RE: Ban Script - brett7 - 10-08-2009

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" "


RE: Ban Script - Headshot - 10-08-2009

Great, thanks for this man.


RE: Ban Script - brett7 - 10-08-2009

np Smile


RE: Ban Script - Project Evolution - 10-10-2009

Nice simple ban script. Good job. Smile


RE: Ban Script - Spl3en - 10-13-2009

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


RE: Ban Script - manipulate - 10-20-2009

(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.


RE: Ban Script - ethical_john - 10-21-2009

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.


RE: Ban Script - Gaijin - 10-21-2009

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