Security Code Verification Using PHP

October 29, 2009

Security code Verification is used for security test to determine whether or not the user is human. Here is a simple security code Verification Script that Generate the code Dynamically.

<?php
$im = ImageCreate(120, 30);  //create image
$white = ImageColorAllocate($im, 255, 255, 255);  //Allocate color for  image
$black = ImageColorAllocate($im, 50, 50, 50);
$string = md5(rand(0,9999));  //Generate a random value and Calculate the md5 hash of the string
//echo $string;
$string=substr($string,1,7); //Return part of a string
$verification = $string;
ImageFill($im, 0, 0, $black); //Fill the Image
ImageString($im, 5, 30, 10, $verification, $white); //Draw the string
Imagejpeg($im, “verify.png”); //Create the Image as ‘png’ format
ImageDestroy($im);  //Destroy the image
?>
<form method=”post” action=”image_verification.php”>
<input type=’hidden’ name=’secretcode’ value=’<?=$verification?>’>
Type Code from Image:
<input type=’text’ name=’code’>
<img src=’verify.png’ border=’1′>
<input type=’submit’ name=’submit’ value=’Submit’>
</form>

<?php
if(isset($_POST['submit']))
{
$code = $_POST['code'];
$secretcode = $_POST['secretcode'];

if($code!=$secretcode){
print “<font color=’red’>Verification failed</font>”;
}
else{
print “<font color=’green’>Verification Success</font>”;
}
}
?>

Entry Filed under: PHP. Tags: , .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


My Fav




My twiTTer

Error: Please make sure the Twitter account is public.

Top Clicks

 

October 2009
M T W T F S S
« Jun    
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Category Cloud

JAVA Java Script MySQL Networking(CISCO) PHP Template Uncategorized

Recent Comments

Zaman on Connecting MySql With Jav…
Rahul on Connecting MySql With Jav…
pollobcse05 on About
মাহমুদ ফয়সাল on About
pollobcse05 on Connecting MySql With Jav…

Blogroll

Meta

My Flickr Photos

SDC12881

SDC12818

SDC12808

SDC12802

SDC12794

More Photos

Pages

Blogroll

Meta