Archive for March 16th, 2007

A Simple Mathcha

If you’ve ever visted the home of my text messaging sites, freetext.biz you may have noticed it has a contact form. Lately, I’ve been getting about 100 messages / day on the contact form. The problem with that though, is that only 1-2 of them are from actual humans. The rest are from spam bots sending me URLs.

I’m not sure why a spam bot would want to send me a URL in my email, but that’s their perogative.

Anyway.. you’ll notice now that I added a simple math captcha to the form. Here’s what it looks like:

mathcha form

Why did I choose a mathcha instead of the standard image? It’s because I think that images are sometimes hard to read, and usually annoy visitors. Don’t believe me? Check out this ticketmaster example:


bad ticketmaster captcha

(note: captcha is an acronym for completely automated public Turing test to tell computers and humans apart… mathcha is a made up word that really means math captcha)

If you want to do something similiar, here’s how you can do it in just about 10 lines of code:

on your form page:

session_start(); // assume this is the top of your file
srand((double)microtime()*1000000);
$num1 = rand(1,10);
$num2 = rand(1,10);
$_SESSION['mathcha'] = $num1 + $num2;
echo "Please Add" . $num1 . " and " . $num2 . ": ";
echo "<input type=text size=2 name=mathcha>";
?>

on your form handler:

session_start(); // assuming this comes first
if ($_SESSION['mathcha'] != $_POST['mathcha'] && trim($_POST['mathcha']) != "") {
echo "hey, you can't add!";
die; // or redirect back
}
// rest of form processing goes here

There ya go. That’s a 30 second mathcha. Feel free to use it however you want. I know it’s really simple stuff, but let me know if it actually helps anybody.

2 comments March 16th, 2007


About Me Subscribe to me on FriendFeed

Name: Ryan Jones
Alias: HockeyGod
Location: Michigan
Company: Identity.net
Title: Sr. Mgr, Prod, Mktg
AIM: TheHockeyGod
Pets: Who Dey

Buy My Book

My Websites

NoSlang
FeedButton
Translate British
TextBunch
No Swearing
Fail Pictures

Twitter

    Recent Shoutwire Editorials

    Recent dotCULT Posts

    Calendar

    March 2007
    M T W T F S S
    « Feb   Apr »
     1234
    567891011
    12131415161718
    19202122232425
    262728293031  

    Posts by Month

    Posts by Category

    Subscribe To RSS Feed

    Link Me





    Random Fail