-
October 11th, 2015, 09:21 PM
#1
Junior Member
How to make HTML form with CAPTCHA?
Dear all,
I am facing a problem that how to make HTML form with CAPTCHA.
Any help in this regard will appreciate.
With Regards
-
October 12th, 2015, 11:31 AM
#2
-
March 1st, 2016, 06:53 AM
#3
Banned
2
down vote
Step 1
You need some code to generate a graphical font image representation web captcha. you must have GD library for generating font image.
<?php
session_start();
$RandomStr = md5(microtime());
$ResultStr = substr($RandomStr,0,5);
$NewImage =imagecreatefromjpeg("bgimage.jpg");
$LineColor = imagecolorallocate($NewImage,233,239,239);
$TextColor = imagecolorallocate($NewImage, 255, 255, 255);
imageline($NewImage,1,1,40,40,$LineColor);
imageline($NewImage,1,100,60,0,$LineColor);
$font = imageloadfont("font.gdf");
imagestring ($NewImage, $font, 5, 5, $ResultStr, $TextColor );
$_SESSION['originalkey'] = $ResultStr; //store the original coderesult in session variable
header("Content-type: image/jpeg");
imagejpeg($NewImage);
?>
Step 2
Now your form to call captcha.
<form action="submit.php" method="post" name="form1">
Name:
<input type="text" name="name" value="" /> <br />
Email Address:
<input type="text" name="email" value="" /> <br />
Message:
<textarea name="message" cols="30" rows="6"></textarea> <br />
<img src="php_captcha.php" />
<input name="captcha" type="text" id="captcha" size="15" /> <br />
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="clear"/>
</form>
Step 3
Now this is last step to form submiting time check capcha validation. Using session information.
<?php
$originalkey = substr($_SESSION['originalkey'],0,5); //session of captcha
$captcha = $_REQUEST['captchacode'];
if($captcha!=$originalkey){
print_error("<b> Captcha does not match, Go back and try again.</b>");
}
?>
Similar Threads
-
By AaronMaxwell in forum Site Feedback/Questions/Suggestions
Replies: 1
Last Post: September 14th, 2012, 04:57 PM
-
By codenamevirus in forum Web Development
Replies: 4
Last Post: January 17th, 2006, 11:29 PM
-
By cybermonk in forum Programming Security
Replies: 5
Last Post: June 25th, 2003, 09:00 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|