As part of my online contact form I grabbed some pieces of code from various places for a number of purposes like string validation and IP blocking.
It's with the IP blocking that I hope I can get some help. Unfortunately I can't remember where I lifted important bits of this section from, so the first step is trying to understand the complete effect of the preg_split.
Currently I can have a list of IPs to block, comma delimited. I would very much like to enhance this to support specifying a range of IPs as well.
The last three attempted attacks on my contact form have all come from 81.177.*.* - today's specifically from 81.177.14.19
I want to block out all of 81.177.x.x and would be happy to specify that as 81.177.0.0 to 81.177.255.255
So who can help out in this effort? Below is the code I have now which contains 2 IPs. IPs are read from a data file and are declared in a 'blockIPs' var like so
Code:
blockIPs: 81.177.38.2, 81.177.14.19
Code:
$IPsToBlock = preg_split('/,\\s*/',$contactDataFile['blockIPs']);
foreach ($IPsToBlock as $ip)
{
if($_SERVER['REMOTE_ADDR'] == $ip) {
include ("contact_header.php");
print "<h1>We're sorry...</h1>";
print "<p>This page has been configured to disallow submissions from the IP address $ip,
from which you appear to be submitting.</p>
<p>If this is incorrect, please contact us via the message forum linked above.</p>";
die( include ("contact_footer.php") );
}
}