A Simple CAPTCHA Script Using PHP

CAPTCHA stands for “Completely Automated Public Turing test to tell Computers and Humans Apart”, it’s very common functionality to use at the time of submit data to prevent machines access of your website. In this post we will developed CAPTCHA script suing PHP with help of easy three steps.This is very basic captcha which is generated by PHP.

Following files will use in this Captcha Example

  • catpcha.jpg – A Image for catcha
  • captcha.php – This file is use to generate captcha with PHP using PHP session.
  • index.php – This file is use to show captcha image to end user.

You can also check other tutorial for CAPTCHA,

Demo Sample

Captcha-with-php

There are following steps need to add CAPTCHA Using PHP

Step 1-We will put the capcha image in project folder.

This image will used to generate captcha image using PHP GD library.This is a only dependency(GD library) with this example.

Download Image

You can use save as image option as well using right click.

Step 2- We need to create a new file captcha.php file in project and put the blow PHP code into this file.

This file is used to generate CAPTCHA image using GD library and rendered to the view page of project where it will call.

Step 3-We will create template file index.php in project folder and put below PHP code into this file.

Here i am creating HTML form to show capcha image and display captcha validation message to user.

Demo & Download Code Of CAPTCHA Script with PHP

Please feel free to send queries to me using below comment section.