Using PHP and Math To slow down spammers

by Josh Highland on April 29, 2006

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.thumbnail Using PHP and Math To slow down spammers

process.php
process.thumbnail Using PHP and Math To slow down spammers

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

  • digg Using PHP and Math To slow down spammers
  • facebook Using PHP and Math To slow down spammers
  • stumbleupon Using PHP and Math To slow down spammers
  • twitter Using PHP and Math To slow down spammers
  • delicious Using PHP and Math To slow down spammers
  • reddit Using PHP and Math To slow down spammers
  • friendfeed Using PHP and Math To slow down spammers
  • posterous Using PHP and Math To slow down spammers
  • tumblr Using PHP and Math To slow down spammers

{ 2 comments… read them below or add one }

1 dan May 1, 2006 at 10:30 am

Doesn’t this just change what the spam bot will be parsing? If you site is unique in this approach then you’re ok. However, if many people adopt this approach, the bots will be doing math in no time.

I think it is a good idea though; it just needs something else.

2 Josh Highland May 1, 2006 at 10:36 am

I agree with you. I plan on putting the math problem into a good captcha once the bots catch on.

Leave a Comment

Previous post:

Next post: