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($text1, 0, 5);
$_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(120, 30);
$text_color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 10, 5, 5, $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);
?>
You're so awesome! I do not believe I've truly read through anything like that before.
ReplyDeleteSo 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