Camen Design Forum

Banning By IPs


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!


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

Only the original author or a moderator can append to this post.

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

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn