Hi,
This script is useful if you want to restrict the access to some people on your site, based on their IPs. There are 2 lists which can be used: one which has a list of the IPs you want to ban and one which you can use to ban a range of IPs. The script checks both lists and if the Visitor’s IP is in the list then the script will show a message to the user and exit.
<?php
/* List with IPs */
$ban_ip_list = array('68.180.206.184', '64.233.167.99', '207.46.232.182');
/* List with IP ranges. Use the '*' as the range selector */
$ban_ip_range = array('69.*.83.197');
/* Visitor's IP Address */
$user_ip = $_SERVER['REMOTE_ADDR'];
/* Message to output if the IP is in the ban list */
$msg = 'You do not have permission to access this page.';
/* Message to output if the IP is in the ban list */
if(in_array($user_ip, $ban_ip_list))
{
exit($msg);
}
/* Check if the Visitor's IP is in our range's list */
if(!empty($ban_ip_range))
{
foreach($ban_ip_range as $range)
{
$range = str_replace('*','(.*)', $range);
if(preg_match('/'.$range.'/', $user_ip))
{
exit($msg);
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Welcome to My site</TITLE>
</HEAD>
<BODY>
Here is my site content.
</BODY>
</HTML>