我有验证码的问题。在我提供验证码之后,在我联系我们表格中说错误验证码。我可以解决这个问题
header('Content-type: image/jpeg');
$width = 50;
$height = 24;
$my_image = imagecreatetruecolor($width, $height);
imagefill($my_image, 0, 0, 0xFFFFFF);
// add noise
for ($c = 0; $c < 40; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
imagesetpixel($my_image, $x, $y, 0x000000);
}
$x = rand(1,10);
$y = rand(1,10);
$rand_string = rand(1000,9999);
imagestring($my_image, 5, $x, $y, $rand_string, 0x000000);
setcookie('tntcon',(md5($rand_string).'a4xn'));
imagejpeg($my_image);
imagedestroy($my_image);
?>
这是我的js验证
if(document.getElementById("captcha").value==""){
alert("Please type the code shown ");
document.getElementById("captcha").value="";
document.getElementById("captcha").focus();
return false;
}
任何人都可以说出问题是什么。谢谢你们。
答案 0 :(得分:1)
有一点是你应该使用session而不是cookie。
另一件事是你可能忘了检查md5。