Best Captcha Scripts

Tonight I decided to evaluate a few different captcha options. I did this mainly for the same reason I do most things on this blog, I have a client that needs a captcha. My situation, as usual, is unique because I have to add a captcha to a PHP page, but that PHP page submits a form to a cgi script. As you may have heard, I am mostly a PHP programmer, so I don’t care much for cgi and asp type scripts. I had to find a captcha that would work with both PHP and cgi, which wasn’t easy as it turns out.

Here are some of the captcha solutions I tried. If you want my best reccomendation, skip to the last one, Jafty Captcha. It is a custom simple captcha I made from what I learned examining the others.

BotDetech

Botdetct is a captcha solution that offers solution in PHP, ASP, cakePHP, Ajax and others, so I thought it might work for my unique situation. Turns out it wasn’t the best for my situation, but it would of been great for pure PHP or HTML web pages that need captcha. I did make a working example which you can see at:

http://jafty.com/BotDetect-PHP-CAPTCHA/samples/php_basic_captcha_sample/ian.php

That is a link to the test I ran with it. The only problem with this is that is does the captcha after the form is submitted and I needed a script that can do the captcha check before form is submitted due to the fact that my client’s page submits to a cgi script and I’d rather not mess with the cgi script at all to keep things simple. Back to the drawing board for me, but if you have a PHP only form submission, it would work great for you!

Simple PHP Captcha

Simple PHP Captcha was the next service I evaluated. I like this one better than BotTech for sure, but again, it was a PHP only solution basically offering no JavaScript alternative and the code to check the captcha would have to be on the page you are submitting the form to. This is a good PHP only solution, but if you are not submitting your form to a PHP script, this isn’t ideal, so I kept searching. Here is the example I made for this captcha script though:

http://jafty.com/captcha/test.php

Simple JavaScript Captcha You Can Add to Any Form

I found my next Captcha to test at http://www.tothemoon.com/2013/01/simple-javascript-captcha-you-can-add-to-any-form/ and you can see from the URL, it is supposed to be a very simple JavaScript captcha. So I decided to give it a go. I actually took this script and made some adjustments to it and came out with a decent captcha script which I will post the code for anyone else interested here.

Demo: http://jafty.com/simple-js-captcha/JS-captcha.html

HTML & JavaScript code:

<!DOCTYPE html>
<html>
<head><title>JS Captcha by Ian L. of Jafty.com</title>
<style>
body{
background-color: #430000;
}
</style>
</head>
<body>
<form name=”review” ACTION=”newpg.html” METHOD=”POST” onsubmit=”return checkform(this);”>
<font color=”#DD0000″>Enter Code ></font> <span id=”txtCaptchaDiv” style=”background-color:#A51D22;color:#FFF;padding:5px”></span>
<input type=”hidden” id=”txtCaptcha” />
<input type=”text” name=”txtInput” id=”txtInput” size=”15″ />
<input type=”submit” value=”Submit”/>
</form>

<script type=”text/javascript”>
function checkform(theform){
var why = “”;

if(theform.txtInput.value == “”){
why += “- Security code should not be empty.\n”;
}
if(theform.txtInput.value != “”){
if(ValidCaptcha(theform.txtInput.value) == false){
why += “- Security code did not match.\n”;
}
}
if(why != “”){
alert(why);
return false;
}
}

//Generates the captcha function
var a = Math.ceil(Math.random() * 9)+ ”;
var b = Math.ceil(Math.random() * 9)+ ”;
var c = Math.ceil(Math.random() * 9)+ ”;
var d = Math.ceil(Math.random() * 9)+ ”;
var e = Math.ceil(Math.random() * 9)+ ”;

var code = a + b + c + d + e;
document.getElementById(“txtCaptcha”).value = code;
document.getElementById(“txtCaptchaDiv”).innerHTML = code;

// Validate the Entered input aganist the generated security code function
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById(‘txtCaptcha’).value);
var str2 = removeSpaces(document.getElementById(‘txtInput’).value);
if (str1 == str2){
return true;
}else{
return false;
}
}

// Remove the spaces from the entered and generated code
function removeSpaces(string){
return string.split(‘ ‘).join(”);
}
</script>

</body>
</html>

BotBoot Captcha

A very simple captcha that requires that the use answer a simple math question. It is not quite secure enough to use for the client I have right now, but might be good for sites with less traffic and spam issues. It would be more secure if it would use questions like “six + one = ?” instead of “6 + 1 = ?” so the math could not be calculated by a bot, but it is a start. I might develop this out in the future to include words instead of numbers or a combination of both as I have seen on many sites and works great. Here is the simple version right out of the box I found:

http://jafty.com/botboot-captcha/

 Jafty Simple Captcha

Okay from everything I’ve learned examining the available simple captcha solutions around the web, I decided to make my own since none of the above quite met my client’s specific requirements. I would consider this to be the ultimate simple captcha. It is HTML5 compliant, cross browser capable, Works on both Windows and Mac and is still relatively simple and very easy to install.

DEMO: http://jafty.com/Jafty-Captcha/simple-captcha.html

DOWNLOAD: Click Here to Download

One Reply to “Best Captcha Scripts”

  1. Hmm it ⅼooks ⅼike your website ate my first cοmment (it
    was extremely ⅼong) ѕo I guess I’ll jսѕt sum it up ԝhat I submitted
    ɑnd say, I’m thօroughly enjoying ʏour blog. I too
    am an aspiring blog writer but I’m stіll new tο the whole thing.
    Do yoᥙ have any suggestions for inexperienced blog writers?
    Ӏ’d genuinely appreciate іt.

Leave a Reply

Your email address will not be published. Required fields are marked *