Forum Moderators: coopster
I log all visits to my site in a mysql-database, and if a visitor visits more than say 50 pages within a 24 hours time frame the script below writes to .htaccess, denying him further access:
$result = mysql_query("SELECT ip,visits FROM iplogging WHERE ip = '".$ip."'");
$row = mysql_fetch_array($result);
if($row[visits]>=50){
$filename = ".htaccess";
$fp = fopen($filename,'a+');
fwrite($fp,"deny from $ip \r\n");
fclose($fp);
}
There are however some ip-addresses that I'd like to white list (e.g. google, slurp, myself) - how can this be done most effectively? How would I add to the above script that it shouldn't tell .htaccess to blacklist Google ip addresses ranging from 66.249.64.0 - 66.249.95.255?
Thanks for your help.
Best
Tanx
Thanks for your thoughts
I have a number of regularly returning visitors that have a fake google-user agent string:
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
All they do is spam my online mail form with useless garbage and junk. I would hate to include these ip's in my white list based on user agent alone - therefore I opted for the ip-solution a long time ago.
The optimal solution for me would be that I could just add the ip range '66.249.64.0 - 66.249.95.255' inside the php-script above itself. - Can this be done somehow?
Best regards,
Tanx
you just have to put some code at the top and bottom of every page, and then it writes a 0-byte size file into a directory, which checks against the user's IP. you can amend the settings to block them out after however many page views (and let them back in after however many minutes or hours, if you want). you can also set it to allow so many page views within however many seconds. so there are two ways to block them.
and... it's got a whitelist too. it already contains the values to allow googlebot, slurp and all the others, and it is a simple matter to add new ones as needed.
it is a very good little script. you should check it out. and because it's written by the people here at webmasterworld, you shouldn't have any problem getting help with it if it plays up.