Yes you read it right…! 5 lines of code :)

I know its hard to believe but this has to be one of the simplest implementation of Captcha, mainly because i can’t find any easier ones.

So here goes, this is how it works:

At the top of the page with the form you want to Captcha protect add these 3 lines of code, this generates the Captcha and adds it all to a nice variable to print out later:

    require_once(‘captcha.class.php’);

    $captcha = new Captcha;

    $captchaImage = $captcha->create();

Then in your form where you want the Captcha, usually at the bottom, just above the submit button add this line, enclosed in php tags of course, this adds the captcha elements to the form:

echo $captchaImage;

So that is the form part done, now we just need to verify what the user has put in. For this i am going to assume that you are verifying atleast one part of the users input, so we need to add this line into it:

$captcha->verify($_POST[$captcha->captchaInputName]);

This would probably fit into your current checking like so:

if($someothervariable && ($captcha->verify($_POST[$captcha-> captchaInputName])) {

Of course we have to add these 2 lines at the top of this processing page aswell (these are not included in the ‘5′ because they have already been added.

    require_once(‘captcha.class.php’);

    $captcha = new Captcha;

And thats it, the class handles everything else, well you have to put the files on your web-server, create a new directory to store the images and make it writeable, but thats a one-shot 10 second job!

Now for a screenshot:

Now for demo and the code:

Captcha DEMO

Captcha Formatted Source 

Captcha ZIP