I put the attached script together to try to do something about the bots that don't honor robots.txt, and that don't provide a decent user agent so we can combat them in our .htaccess file. The recent abuse of a few Wunderground scripts highlights the need for the best defense possible.
I've included it at the very beginning of my problem scripts and it's working well in testing. It uses PHP session() to try to sense and control the miscreants, but won't help with bots that have "patience". The last flood that I observed on my server had many very rapid hits so this is to stop those.
The comments in the script should explain everything that's going on. Feel free to use it and let me know if you have any ideas for improvement.
- Jim