Forum Moderators: coopster

Message Too Old, No Replies

IP blocking script

         

cyberdyne

12:58 am on Feb 12, 2012 (gmt 0)

10+ Year Member



Im trying to create an IP blocking script that I can implement only on necessary pages as opposed to using .htaccess which although effective is a little to powerful for my needs.

I have the following scripts but do not know how to incorporate the two so that the resulting script will allow a lookup of IP's in a .php or .ini file (eg: banlist.php) and feed that user the resulting message.

Any help getting this working would be greatly appreciated.
Thank you in advance

1.
$blockip = file($file)
if (in_array($_SERVER['REMOTE_ADDR'], $bannedlist))
{
echo "You Have Been Banned from using this page";
exit();
}


2.
$blockip = array(
'1xy.2xy.3xy.4xy'=> 'You\'ve a spammed !',
);

foreach($blockip as $key=>$val)
{if ($_SERVER['REMOTE_ADDR'] == $key)
{
die("You Have Been Banned from using this page because<br><br> $val");
}
}

cyberdyne

10:45 am on Feb 12, 2012 (gmt 0)

10+ Year Member



Found a pretty good alternative if anyone is interested: mrmagne.com/spamip/ (SpamIP)