php CAPTCHA library

I just came across this awesome CAPTCHA library in PHP. It generates and validates CAPTCHAs internally to your website, allowing you to secure your input and contact forms etc from bots and crawlers.

You can download it here, or visit the home site here.

A CAPTCHA (Wikipedia article) is used to secure input through forms from spam via web-bots submitting. They provide a distorted image which is difficult for visual software to interpret, but easy to the human eye and mind. This library also provides for you to use an audio CAPTCHA for your visitors. The name CAPTCHA is derived as an acronym for “Completely Automated Public Turing test to tell Computers and Humans Apart”.

How to use the library:

Step 1:

Download the zip file here and unzip into your site directory.

Step 2:

Save the below as a file called visual-captcha.php in the same directory

$aFonts = array('fonts/VeraBd.ttf', 'fonts/VeraIt.ttf', 'fonts/Vera.ttf');
$oVisualCaptcha = new PhpCaptcha($aFonts, 200, 60);
Step 3:

Next save this as index.php, again in the same directory

<title>Visual CAPTCHA demo</title>

if(isset($_POST['user_code'])) {
    if (PhpCaptcha::Validate($_POST['user_code'])) {
        echo 'Valid code entered';
    } else {
        echo 'Invalid code entered';

<p><img src="visual-captcha.php" width="200" height="60" 
alt="Visual CAPTCHA" /></p>
<form method="post" action="">
<input type="text" name="user_code">
<input type="submit">

Step 4:

Navigate to index.php, and voila!!

This is a very rudimentary form for demonstration purposes, however it allows you to see the CAPTCHA in action.


About Cameron
I'm a final year Computer Science/Information Systems major. Already finished my BA in Politics/Philosophy. I do web and software freelance on the side, while I finish studying. Hoping to be self-employed by the end of my degree, otherwise off into the real-world I go....

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: