I try to implement php image verification code, here is in test.php
file:
<form method="POST" action="processor.php">
<div style="float:left;">Code: <input type="text" name="verif_box" style="cursor:text"> </div>
<div style="margin-top:0px;position:relative;left:5px; top:-8px;"><IMG SRC="image.php"></div>
<input type="submit" name="submit" value="Submit">
</FORM>
Here is image.php
:
$width = 60;
$height = 24;
$my_image = imagecreatetruecolor($width, $height);
imagefill($my_image, 0, 0, 0xFFFFFF);
for ($c = 0; $c < 110; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
imagesetpixel($my_image, $x, $y, 0x000000);
}
$sessioncode=rand(0,9999);
imagestring($my_image, 5, 0, 0, substr(strtoupper(md5("Mytext".$sessioncode)), 0,6), $textcolor);
setcookie('tntcon',(md5("Mytext".$sessioncode)));
imagejpeg($my_image);
imagedestroy($my_image);
exit();
Here is processor.php
:
$verif_box = $_POST["verif_box"];
if (strtoupper($_COOKIE['tntcon']) == strtoupper($verif_box)) {
echo "right code";
} else {
echo "wrong code";
}
The problem is that, even I input the right verification code, in the processor.php file always give me "wrong code" message, what I am doing wrong?