Created
June 29, 2018 07:11
-
-
Save niravmadariya/87bb14882b8332acfa909535fbc6b145 to your computer and use it in GitHub Desktop.
Signup Form with Captcha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Sign Up Form</title> | |
</head> | |
<body> | |
<section> | |
<form class="c-form" action="" method="POST"> | |
<div> | |
<h2>Sign Up</h2> | |
<label for="name">Name</label> | |
<input type="text" id="name" name="name" maxlength="100" placeholder="First Name Last Name" required> | |
<label for="email">Email</label> | |
<input type="email" id="email" name="email" maxlength="100" placeholder="[email protected]" required> | |
<label for="password">Password</label> | |
<input type=Password minlength="8" maxlength="16" id="password" name="password"placeholder="password" required> | |
<label for="Captcha">I'm Not Robot | |
<? | |
session_start(); | |
$captcha_code=substr(md5(microtime()),0,5); | |
$t=-1; | |
$im=imagecreatefromjpeg("../captcha/123.jpg"); | |
$font_file='../captcha/BRADHITC.ttf'; | |
$black=imagecolorallocate($im,3,0,0); | |
for($i=0;$i<5;$i++) | |
{ | |
$s=$captcha_code[$i]; | |
imagefttext($im,rand(15,25),pow($t,$i) *rand(0,20),(20*($i+1))+5,25,$black,$font_file,$s); | |
} | |
imagepng($im,'../login/test'.image_type_to_extension(IMAGETYPE_PNG)); | |
$_SESSION["captcha_code"]=$captcha_code; | |
echo "<br /><img src=test.png /><br />"; | |
?> | |
</label> | |
<label for="captcha">Enter Captcha | |
<input type=text name=captcha_code placeholder="Captcha Code"> | |
</label> | |
<label><input type="checkbox" checked="checked">I Agree to User Terms and Conditions</label> | |
<div class="c-form-controls"> | |
<button type="submit">Sign Up Now</button> | |
</div> | |
</div> | |
</form> | |
</section> | |
</body> | |
</html> | |
<?php | |
if(isset($_SESSION['captcha_code'])){ | |
if($_POST['captcha_code'] == $_SESSION['captcha_code']) | |
{ | |
unset($_SESSION['captcha_code']); | |
echo "Signed up Successfully."; | |
} | |
else{ | |
echo "Invalid captcha code.!!!"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment