note 79560 deleted from ref.image by felipe
| From: | felipe@php.net | Date: | Mon, 24 Dec 2007 01:43:46 +0000 |
| Subject: | note 79560 deleted from ref.image by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133922@lists.php.net to get a copy of this message | ||
Note Submitter: pradipsomani at gmail dot com
Reason: 1
----
Image Verification using GD for any form.
form.php
<?php
session_start();
//echo $_SESSION['string'];
if (isset($_POST['submit'])){
if($_SESSION['string']==md5($_POST['pass']))
{
echo "correct code";
}
else
{
echo "incorrect code try again";
}
}
?>
<html>
<body>
<form action="form.php" method="post" name="check">
Email : <input type="text" name="email">
<img src="assign.php"><br><br>
<input type="text" name="pass">
<input type="submit" name="submit" value="Check">
</form>
</body>
</html>
=====================================
assign.php
<?php
session_start();
function makerandom($minlength, $maxlength)
{
$characters = "0123456789";
if ($minlength > $maxlength)
{
$length = mt_rand ($maxlength, $minlength);
}
else
{
$length = mt_rand ($minlength, $maxlength);
}
$totallen=strlen($characters)-1;
for ($i=0; $i<$length; $i++)
{
$result=$result.$characters[mt_rand(0,$totallen)];
}
return $result;
}
$try=makerandom(4,8);
$_SESSION['string']=md5($try);
onrefresh($try);
function onrefresh($str)
{
$image=imagecreate(150,70);
// something to get a white background with black border
$back = imagecolorallocate($image, 0, 0, 0);
$border = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, 149,69, $border);
imagerectangle($image, 0, 0,149,69, $back);
$textcolor=imagecolorallocate($image,255,0,0);
//to write string in image
imagestring($image, 5, 40, 25, "$str", $textcolor);
header('Content-type:image/png');
imagepng($image);
}
?>
=====================================