CAPTCHA - Tell Computers and Humans Apart

CAPTCHA is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart".

The use of CAPTCHA is to challenge the computer that is unable to solve (Only Humans can solve) and some examples like solving through seeing or basic mathematical questions. In some websites (preventing spams) , they also use CAPTCHA in their forms. Generate images that only Humans can see, and Computers or spam bots unable to Solve.

CAPTCHA is very easy to create in PHP Programming with the help of PHP image functions and sessions.


First is to create a SESSION, (hidden string):
*use session_start();
*Create a function that will generate random STRING like a,b,c and 1,2,3.
*Use loop statement to limit your characters.
*use rand(); to generate your random characters.
*Assign to $_SESSION['captcha'] to store your hidden string in the session (invisible in the browsers).

Generate Image in the FORMS:
*Create a phpfile image.php to show the image of the hidden string.
*use session_start();
*to generate image, use png, gif or jpg datatype, header("Content-type: image/png");.
*use imagestring(); function to print the hidden string in the image, you may also use any necessary image functions in the PHP.
*The last codes should be..... imagepng($image); imagedestroy($image); to clean up.


Processsing the FORM:
*Create a script that will check each field of the form. Your first priority to check is the HIDDEN STRING in the Session.
* access the $_SESSION['captcha'] then compare it to the user's input.


The Procedures above are the basic structures of the CAPTCHA code of PHP. And it is very simple and very effective. You can tell that only humans can READ the hidden string in the generated image. If we added more colors and random arrangements of the Characters, it creates more complications and that is impossible to identify by computers, they don't have visual capabilities.

0 comments: