Camen Design Forum

Delete

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

To delete this thread, and all replies to it, you must be either the original author or a designated moderator.

Banning By IPs

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*
First create a file named banned.php use the script below

%
<?php 
// 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: https://google.com");   //this is where you send banned ips
 exit;
}
?>
%

*Second*
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.

*Third*
You will have to add

%
require_once("banned.php");
%

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

Thats it!

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn