View Full Version : Banning IP Address's using PHP


kicker91
11-22-2003, 02:44 PM
Some of us who are hosted can't use .htaccess. And some of us have no clue what .htaccess is or how to use it. Well, if you have PHP on your server, you can ban IP's easily! Just place the following code on the TOP of every page on your site:

<?php include("ban.php"); ?>

You may need to set it to your local path.

Next, create a file called ban.php. Copy and paste this onto the file:

<?php
$banned_ip = array();
$banned_ip[] = '00.000.000.00';
foreach($banned_ip as $banned) {
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == $banned){
echo "You have been banned.";
exit();
}
}
// BANNED IP'S WILL NOT SEE ANYTHING BELOW THIS.
?>

Change

$banned_ip[] = '00.000.000.00';

to the IP you want. You can copy and past that for as many IP's as you want to ban.

You can also change
echo "You have been banned.";

to any message you want. (Between the quotes)


Have fun!