In my ongoing effort to stop comment spam from getting through, I've decided to implement IP address blocking and referrer blocking. I never really wanted to block IP's or visitors from certain referrers from accessing my entire site, but decided to build a little script to do so anyways. I guess I should start being a little tougher on these spambots.

So creating this was pretty simple. I first just created a new table in my MySQL database with a unique id field, IP address field, referrer field, active field, reason field, and datetime field. Each row will either contain info in the IP address field or the referrer field as well as the others. The active field is just a little flag where I can enable or disable the ban on the IP/referrer. The reason field is just a text field where I can type in a reason as to why I created this block in the first place. And the datetime field is just a timestamp of when the block/ban was created.
Next I just created a script on my admin page where I could easily add, edit, and delete items in this database table. Finally, I just had to implement this block/ban on the main site, and since my blog runs on a template system, doing this was easy. I just edited my main template script and put a if/else statement in there. For example, if the visitor's IP address or referred is in the database table and active, then redirect them to the blocked.html page (seen above), else execute the template script like normal.
So far, this has worked great. The spambots that were still getting through my various anti-spam techniques all had the same IP address or came from the same referrer. So I simply added that IP and referrer into the database and I haven't seen a spam comment from them since *knock on wood*. I'm sure it's only a matter of time before they realize this and change their IP address or use a different referrer, but what the hell, at least it stopped them for the time being.

May 09, 2007 11:37 am
1590 Views

My first post from our new house
Another issue with the captcha right now is my damn host. They keep breaking the Imagemagick binaries, which I use to build that random image. It's broken again right now and they have yet to fix it. So even if I wanted to enable right now, I couldn't.