PHP Captcha Demo - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Captcha Demo - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript


Post Top Ad

Post Top Ad

Thursday, June 15, 2017

PHP Captcha Demo

PHP Captcha Demo

PHP captcha

Since we Know Captcha is very Important for our site to prevent our site from misuse or spamming then we will use captcha then attackers or bots not spam in our site.Lets start Creating PHP Captcha for our site.

First : form.php
Code :

<title>Check It</title></head>
<form action="val.php" method="post">
<img src="captcha.php">
Enter Image Text
<input type="text" name="cap">
<input type="submit" name="s" value="Submit">

This is simple html form where we print our captcha and input box for captcha value input then we validate its true or false.

Second : captcha.php
Code :

session_start(); //Starting Session
$code=rand(100000,999999); //Random Number
$_SESSION['code']=$code; //Storing Captcha vallue in session

//Creating Image in Png fomat

//Destroying Image

This is Captcha generating page it generates captcha in png image format and store captcha value in session then we check the session captcha value and user captcha value are same or not.

Third : val.php

$a=$_POST['cap']; //receiving cap value from form
$b=$_SESSION['code']; //Getting Captcha Value from Session

//Comparing User Captcha value and Session Value
if(isset($a) && $a !="" && $b==$a)
echo "correct code enter"; //True Captcha
die ("wrong code entered"); //False Captcha

In The Last Page val.php we check captcha is true or false.

Thank You


  1. Firstly thanks a lot for such a wonderful post. I would like to know more about such topics and hope to get some more helpful information from your blog.
    Best Web Development Company in India

  2. am regular reader of your blog and no doubt it all stuff is awesome. The best thing about your sharing and posting is that you always provide content that is helpful for both the newbie and experts.

    White Label Website Builder

  3. Thanks for sharing the valuable information here. So i think i got some useful information with this content. Thank you and please keep update like this informative details.

    AWS Training in Chennai

    SEO Training in Chennai

  4. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Android Training in Chennai
    Ios Training in Chennai

  5. For the hell of it I thought it'd be wonderful to have the ability to build them. So here's what I developed . You'll need imagemagick installed. 2captcha bot


Post Top Ad