Combating Comment Spam

Three times in the last week I received comment spam. If you happened across it while reading one of my entries, I apologize for not getting to it quickly enough. All traces of those comments should be gone, but if you notice more, please let me know about it. Ads for penis enlargement simply aren’t wanted here.

In any case – traffic to my blog is pretty low, with the possible exception of the page on the Angler Fish, which seems to be gaining in popularity by the day. Since traffic is low, it’s easy for me to police comments. While I have no illusions that traffic might pick up greatly, there’s always the chance, and let’s face it – I’m lazy. I don’t want to spend my day making sure that the comments stay free from spam.

Luckily, the Movable Type comment interface will return you an IP address for each person who leaves a comment. Sure, you can require an email or web address too, but those are easy enough to fake. Even if they aren’t fake, they don’t help much. I just don’t want to spend the time dealing with it if at all possible.

So I came up with a solution using PHP to block the IP address of the spammer. This may get unwieldy pretty quickly, but for the time being I think it’ll work pretty well. There is a danger of blocking someone else using the same dynamic IP address at a different time – but that’s just going to be a risk I have to take.

I simply added this snippet of code to the top of each of my pages. Not that I manually updated each page. I already make use of another PHP construct to import the contents of a banner page into each of the other pages. So I just pasted this in the banner, whereby it gets pulled in elsewhere:

<?php if(getenv (“REMOTE_ADDR”) == ‘999.999.999.999’) exit (“This IP address has been used to post spam to this weblog. As a result, you are no longer welcome here.”); ?>

When a user hits the page from 999.999.999.999, instead of seeing the blog, they will get a message informing them of my actions. I chose to place the code in the banner page, as opposed to the header, so that the page information and meta data will be available if they’d like to view that to find an RSS feed or something. If that doesn’t matter to you, put it as high on the page as you like!


Posted

in