I tried the script change and it will block a full IP but not a partial IP such as 172.190 or 172.190.
The original script blocked the partial IP but could not access the database and unfortunately I do not know how to fix it.
This is really strange, because I have tested the code in my server and it works perfectly. Note that it works either with or without the second dot with no problems. Basically what I did was to use same method to match banned ips to current ip as, however using the built-in mysql functions, which is faster than retrieving the complete database into php and then applying search rules on these results.
But if you still insist on usign your code, it should look something like this:
<?php
$result = mysql_query('select ip from banned.ip');
$count = mysql_num_rows($result);
$iplist=array();
for($i=0;$i<$count;$i++)
{
$row=mysql_fetch_row($result);
// the list of banned IPs, including partial IP addresses
$iplist[$i] .= $row['0'];
}
$ip = getenv("REMOTE_ADDR"); // get the visitors IP address
// echo "$ip";
$found = false;
foreach ($iplist as $value) { // scan the list
if (strpos($ip, $value) === 0){
$found = true;
}
}
if ($found == true) {
echo "top.location = \access_denied.php\";\n"; // page to divert to
}
?>
Hope it works.
By the way, is this php script part of a javascript, because top.location is not php's function for sending headers?