300x250 AD TOP

Text Widget

Total Pageviews

9,608

Subscribe us

Contact Us

Name

Email *

Message *

Powered by Blogger.

You can also receive Free Email Updates:

Popular Posts

Followers

Sunday, 1 July 2012

Tagged under: , ,

How to create CAPTCHA using PHP

CAPTCHA: Completely Automated Public Turing Test To Tell Computers and Humans Apart.

A CAPTCHA is a program that protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot. For example, humans can read distorted text as the one shown alongside, but current computer programs can't:

The term CAPTCHA (for Completely Automated Public Turing Test To Tell Computers and Humans Apart) was coined in 2000 by Luis von Ahn, Manuel Blum, Nicholas Hopper and John Langford of Carnegie Mellon University.

Generating a simple CAPTCHA and its verification is quiet a simple task using PHP. In this post, I would do the same, but the CAPTCHA generated would be a simple one, while the reader can add his own creativity to it later!!

  • Step I: Create a file captchaimg.php, and add the following code to it:



You can check the above file by opening it in your browser. Everytime you refresh, a new, random alphanumeric string is generated in the CAPTCHA.
  • Step II: Create a form form.php, and add the following code to it:


Now, this is it!! Your basic CAPTCHA is ready!! It will look like below:

Another Example:
For this, you need to include a font file in your project folder. I have used AngelicWar.ttf. Download the font from the download box alongside.
Now, Overwrite the file captchaimg with the following code:


Now, this will result in following CAPTCHA:


For the following CAPTCHA use cheapink.ttf from the download box alongside.



You can enhance it by using two different strings in a single CAPTCHA image, or using some string characteristics.

Want help in creating more creative CAPTCHA?? Feel free to Contact Me.

4 comments:

  1. Very helpful post!! Thanks!!Continue the good work:-)

    ReplyDelete
  2. Nice post..Can you tell me how to do this in Class?

    ReplyDelete
  3. Can you elaborate on your requirements??

    ReplyDelete
  4. You have done creating CAPTCHA in simple php.But can you tell me how to do the same in class like php's oop concept?

    ReplyDelete