Using PHP and Math To slow down spammers

If you read my blog, you might have noticed a LOT of spam in the comments of the posts. I was getting 100+ a day. Getting you blog on the front page of Digg.com will do that I guess. I got tired of all the spam, so I had the server email me a copy if the comment to my T-mobile MDA phone, If I saw the post was spam, I could kill it right away. This got old because I was getting an email every 5 – 10 minutes, way more then I cared to check.

I know that captcha systems help with keeping spam robots out, but at the same time I find them hard to use so I didnt want to put one up. Also, many spam bots look for captchas and can read them now! I thought there had to an easy way to handle the problem.

Step 1
Rename the file that your form posts to. This will break many of the bots and help cut the spam for a little while.

Step 2
Using some simple php, I decided to make users answer a very simple random math problem before their post could be saved. Here is some sample code on how I set it all up.

click the thumbnail images for a larger view of the code

form.php
form.gif

process.php
process.gif

I realize that there are most likely better ways to solve this problem, like having the random numbers be displayed in images that are dynamically generated, and I will do that If this menthod fails. For right now it seems to be working. I hope that it works for you.

DOWNLOAD THE SOURCE CODE