Home > PHP/MySQL Programming > Our fight against spammers continue…

Our fight against spammers continue…

March 26th, 2007

Form spammers are one of the most annoying things facing website owners and developers. These are the guys which create automated bots to fill in your forms with spam, in the hope that it will be posted on your website. Thankfully, there are ways around this!

Our blog is constantly under attack from these spammers and so we’re always adapting our website to counteract their work. Today, we implemented a security code feature, also know as a CAPTCHA. You may have seen these on many websites, which require you to type in a code which is displayed in an image.

This CAPTCHA prevents automated spam bots from successfully completing a form, since they are not clever enough to read the security codes (although I’m sure they’ll crack it one day - and then we’ll develop a new system, which they’ll crack, and then we’ll create a… you get the idea.).

The CAPTCHA is not an ideal solution by far and we regret to resorting to these measures. The reality is that you will see a lot more of this over the next few years as spam bots develop and website owners increasingly fight back.

Create your own CAPTCHA!

We will shortly write an article on preventing spammers with a tutorial on how to implement a CAPTCHA facility into your website. In the meantime, here’s a quick fix to stop 75% of spam using the popular server-side programming language; PHP.

Check the Visitor’s Browser
Using PHP we can check the browser of the visitor completing your form. Most spammers do not identify themselves with a browser so we can easily check this using the following code:

<?php

#get the browser name (tag)
$browser = $_SERVER['HTTP_USER_AGENT'];

#if the browser is blank send them away
if ($browser == ''){
die("Your browser tag is empty. You must be a spammer!");
}

?>

Further information

To read more information on CAPTCHA’s visit the following useful links.

Bookmark and Share

PHP/MySQL Programming

  1. Archive
    March 25th, 2009 at 17:24 | #1

    Just a quick note on that. Sounds great, but I thought of a varient. Basically im wondering what would happen if a client didn’t have browser headers forwarded. I cant quite envisage how, but sods law states it’ll happen. However, if your protecting form mail then you can re-write the code so that the vital components of the html form are missing like the send button or the e-mail address. ie, if no browser then dont print e-mail address. This will mean that the page will always appear and avoids the embarressment of people not being able to see the site because they have browser headers blocked. Just a thought thats all.

  2. Archive
    March 25th, 2009 at 17:24 | #2

    Its damn annoying, it gets to the point where real responses (like me) feel guilty leaving a comment!

  3. Archive
    March 25th, 2009 at 17:24 | #3

    Only the User Agent is not a good soloutions for this. I would recommend using one of the spider scripts availible. Every Bot has the same procedure. Scanning on site after another. Simply install a spider script that detect a unnormal behavior of “surfing”.

  4. September 10th, 2009 at 14:58 | #4

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  1. No trackbacks yet.