Virtual Brain Online Logo

Bookmark: Root \ PHP \ User Validation With Image Verification Code

User Validation With Image Verification Code

Last Updated: 2007-01-01

Running a website is just like owning your own store on the street, actually it's worse sometimes. A website will attract all kinds of human scum attempting to use your website for their own illegal purposes. Most times these evil crackers will deploy bots, autonomous programs, to send out spam or find weaknesses in your website's design. At lot of harm is done when bots get into forums or contact forms.

A way had to be found to keep robots out and let humans in, this is called CAPTCHA. CAPTCHA stands for "Completely Automated Public Turing test to tell Computers and Humans Apart".
Most major public website use some form of a CAPTCHA test, I will describe two most commonly found picture validation tests below. The Image validation test described here should be able to serve your needs until robots get smart enough to read obscure text or until they gain legal rights not be excluded from human activity ;)

The idea behind image validation is quite simple, generate an image and have a human describe the image. The best way to achieve consistent results is to use common forms of communication. Letters and numbers are the best way to achieve consistency since an "a" will always be an "a" and "3" will always mean "3". Other forms use pictures of items and ask the user to describe them, for our purpose, this is a flawed approach since a white mouse could be described as a mouse. rodent or rat. The last approach does work for verifying identity.

One last point before I present the code, a lot of CAPTCHA examples on the internet generate a few numbers on a solid white background. Even a half blind OCR program from 1990 can read any text generated onto a solid background without trouble. You might as well not waste your time.
Bad CAPTCHA: is using a great system
The Slashdot image is build very well, it is using whole words which aid the person tested to give the right answer the first time. The image is obscured by drawing lines through the word in the same color the word is written in, this prevents a bot program from striping colors to find the word hiding underneath the colored lines. It has two more features which I do not cover here, the word's letters are spaced unevenly and some words switch fonts for a letter or two.

This code is released under the "Ad License", the ad license is quite simple. You are allowed to use the code below for commercial and private use as long as you click on one of the advertisements you find on this page. Please only click on advertisements you are interested in!

PHP4/5 WITH gd plugin - on rpm based linux search for a package called php5-gd or similar. You have to restart your webserver after the installation.

And finally, the code:
Version 1.1 has more backgrounds and more KeyWords

How it works....
The file picks the word and background image randomly from a predefined list.
You can change the list of keywords used by the script on line 6. The script expects a list of comma separated values, please keep your words under 6 characters.
Line 24 allows you to change the background images used.

HumanTest Example

Originally Posted by Skylinux @ 2007-01-1 13:42:01


Comment array mismatch, this is very bad.2.1..2.1