Saturday, April 7, 2012

how to create image captcha in php


     demo.php 
<?php session_start(); 
if (
$_POST["vercode"] != $_SESSION["vercode"] or $_SESSION["vercode"]=='')  { 
     echo  
'<strong>Incorrect verification code.</strong>'
} else { 
     
// add form data processing code here 
     
echo  '<strong>Verification successful.</strong>'
}; 
$text1 =  md5(microtime()); // rand(10000,99999); 
$text substr($text105);
$_SESSION["vercode"] = $text

?> 



<form action="demo.php" method="post" style="width:400px; height:400px; "> 
<img src="demo1.php?str=<?php echo $_SESSION["vercode"]  ;?>" />
 <input type="text" name="vercode" /> 
<input type="submit" name="Submit" value="Submit" /> 
</form>
<?php     // demo1.php    create image 
$text $_GET['str'];

$im imagecreatetruecolor(12030);
$text_color imagecolorallocate($im255255255);
imagestring($im1055,  $text,$text_color);
// Set the content type header - in this case image/jpeg 
header('Content-Type: image/jpeg'); // Output the image
imagejpeg($im);
imagedestroy($im);
?>

1 comment:

  1. You're so awesome! I do not believe I've truly read through anything like that before.
    So good to find another person with a few original
    thoughts on this topic. Really.. thank you for starting this up.
    This website is one thing that is needed on the web, someone with some originality!


    Feel free to visit my page: captcha image verification

    ReplyDelete

If you Satisfied , Please Leave a comment