你这个验证码的图片都是错的。。,先要有个好的验证码图片才能验证啊
yzm.php
//生成验证码图片
session_start();
Header("Content-type: image/gif");
srand((double)microtime()*1000000);
$im = imagecreate(50,25);//设置图片的宽与高
$black = ImageColorAllocate($im, 0,0,0);//设置背景颜色
$white = ImageColorAllocate($im, 255,255,255);//设置文字颜色
$gray = ImageColorAllocate($im, 200,200,200);//干扰颜色
imagefill($im,50,25,$gray);
while(($chk_num=rand()%10000)<1000);
$_SESSION["chk_num"] = $chk_num;
//将四位整数验证码绘入图片
imagestring($im, 15, 5, 1,$chk_num , $white);//5, 5, 1分别表示为字体大小,左边距,上边距
for($i=0;$i<100;$i++) //加入干扰象素
{
imagesetpixel($im, rand()%70 , rand()%30 , $gray);
}
ImagePNG($im);
ImageDestroy($im);
?>
yanzhengma.php
缓存问题,每次获取a.php页面时都要传一个随机数过去,保证每次获取的a.php页面不是缓存后的。location.href="a.php?rand="+Math.random();
你这验证码不好 ,不要用这个.直接是网站下个 jQ 的验证码吧
$_SESSION["code"] = $str; 放到前面。