Camen Design Forum

Banning By IPs

append delete rex

I wanted to be able to ban any trouble makers and here is my solution just incase anyone else needs to do the same.

First create a file named banned.php use the script below

// Let's redirect the undesirables all bans are in blacklist.txt

if ( !file_exists('blacklist.txt') ) {
 $deny_ips = array(
} else {
 $deny_ips = file('blacklist.txt');
// read user ip adress:
$ip = isset($_SERVER['REMOTE_ADDR']) ? trim($_SERVER['REMOTE_ADDR']) : '';
// search current IP in $deny_ips array
if ( (array_search($ip, $deny_ips))!== FALSE ) {
 // address is blocked:
 header("Location:");   //this is where you send banned ips

Now in your root folder you will need to create the blacklist.txt. Inside this text place all ips you need to ban one ip per line.

You will have to add


to the pages you want the bans to be applied too.

Thats it!

Reply RSS


append delete #1. Martijn

As NNF already depends on the .htaccess file for its URL rewrites, you may instead want to ban IP addresses in there.

Take a look at this example from the superb Perishable Press:

One of the great things about blocking access at the .htaccess layer is that Apache will drop the connection for you before it ever needs to spin up PHP to do any parsing. This will be easier on your server as well in case of a DoS attack.

For people who feel more at home with PHP, this is definitely nice to have!


(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn