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

Breaking

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 :

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

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 :

<?php
session_start(); //Starting Session
$code=rand(100000,999999); //Random Number
$_SESSION['code']=$code; //Storing Captcha vallue in session
$im=imagecreatetruecolor(100,40);
$bg=imagecolorallocate($im,80,60,165);
$fg=imagecolorallocate($im,50,255,255);
imagefill($im,5,5,$bg);
imagestring($im,20,30,10,$code,$fg);

//Creating Image in Png fomat

header('content-type:image/png');
imagepng($im);
imagedestroy($im);
//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
Code:

<?php
session_start();
$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
}
else
{
die ("wrong code entered"); //False Captcha
}
?>

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

Thank You

5 comments:

  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete

Post Top Ad