PHP Capthca Image Verification - Web Development and Online Earning

Breaking

Web Development and Online Earning

Learn Web Development ,PHP MySQL,Codeigniter,AJAX,HTML CSS,Javascript,Jquery,Web Hosting,Online Earning,SEO,Link Building,Online Banking and More

test banner

Post Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Wednesday, May 31, 2017

PHP Capthca Image Verification

PHP Advanced Image Captcha

PHP Capthca Image Verification
PHP Capthca Image Verification

Hi Guys Today We will Learn PHP Advanced Image Captcha System with SESSION.
What you Will Need:
Create 3 files name are Given Below.
1.index.php
2.captcha.php
3.style.css
php image captcha
php image captcha

Now Copy the Below codes for Different files.
index.php
Add the below php Codes top of the index.php page to Process and Validate Submited Captcha.
<?php
session_start();
if(isset($_POST['submit'])){
if($_POST["captcha_code"]==$_SESSION["captcha_code"]){
$success="Your Captcha successfully Validate";
}else{
 $error= "Wrong Captcha.Please Type Valid Captcha";
}

}

?>

Add The Below HTML codes after PHP Codes to Display Captcha form.
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css"/>
<title>Advanced SESSION Based Math Captcha with PHP </title>
</head>
<div id="form">
<h2 color="black">PHP Advanced Math Captcha Validation Image</h2>
<form method="post" action="">
<img src="captcha.php"/><br/>
<input type="text" name="captcha_code" placeholder="Enter The Numbers"/><br/>
<input type="submit" name="submit" value="Validate"/>
</form>
<span><?php if(isset($error)){echo $error;}?></span>
<success><?php if(isset($success)){echo $success;}?></success>
</div>
</html>

captcha.php
Add the Below codes for captcha.php to Generate Captcha.
<?php
session_start();
$random_alpha = md5(rand());
$captcha_code = substr($random_alpha, 0, 6);
$_SESSION["captcha_code"] = $captcha_code;
$target_layer = imagecreatetruecolor(80,30);
$captcha_background = imagecolorallocate($target_layer, 455, 360, 319);
imagefill($target_layer,0,0,$captcha_background);
$captcha_text_color = imagecolorallocate($target_layer, 0, 0, 20);
imagestring($target_layer, 8, 8, 8, $captcha_code, $captcha_text_color);
header("Content-type: image/jpeg");
imagejpeg($target_layer);
?>

style.css
Add some CSS Codes to Design Index.page.
#form{
 width:600px;
 height:250px;
 background:#ddd;
 color:black;
}
input[type=text]{
 padding:7px;
 width:50%;
 border-radius:5px
}
input[type=text]:focus{
 border:2px solid black;
 padding:8px;
}
input[type=submit]{
 padding:5px;
 border-radius:5px;
 background:#080808;
 color:white;
}
label{
 font-size:20px;
 color:black;
 font-weight:bold;
}
success{
 font-size:20px;
 color:green;
 font-weight:bold;
}

span{
 font-size:20px;
 color:red;
}

You have Successfully Created PHP Image Captcha System.
Thank you for Visit.

No comments:

Post a Comment

Thank You for Your Comment

Post Top Ad

Responsive Ads Here