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);
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s