How to: Create a CAPTCHA Script with PHP

Share it on Twitter  
Share it on Facebook  
Share it on Linked in  

You likely have encountered CAPTCHA on a number of Websites. It is that small image with a verification code--usually some combination of random words or letters--that you type into a box before submitting something, such as feedback or a comment.

CAPTCHA is a very simple and common protection that helps prevent spam and the automatic submission of an operation by some kind of program or robot. CAPTCHA protection is used on Website forms, such as ours (below), and works by generating a random string, writing it to an image, then storing the string inside of a session. The site then checks the CAPTCHA when the form is submitted.

To learn how to make your own simple CAPTCHA image using PHP, click here for a step-by-step tutorial from our sister site, PHPBuilder.com.