验证码问题求解决
问题:怎样能将图片中的验证码储存起来用于后期的验证?
verficode.php 页面
ob_clean();
for($i=0;$i $num.=dechex(rand(0,15));
}
$num=substr($num,-4,4);
$nowimage=imagecreate(100,30);
imagecolorallocate($nowimage,240,240,240);
for($i=0;$i
$x=mt_rand(1,8)+100*$i/4;
$y=mt_rand(1,50/4);
$color=imagecolorallocate($nowimage,rand(0,150),rand(0,150),rand(0,150));
imagestring($nowimage,$font,$x,$y,$num[$i],$color);
}
for($i=0;$i $randcolor=imagecolorallocate($nowimage,rand(200,255),rand(200,255),rand(200,255));
imagesetpixel($nowimage,rand()%70,rand()%20,$randcolor);
}
header("content-type:image/png");
imagepng($nowimage);
imagedestroy($nowimage);
?>
index.php 页面
<br /><?php<br />session_start(); // 開啓session<br />ob_clean();<br />for($i=0;$i<4;$i++){<br />$num.=dechex(rand(0,15)); <br />}<br />$num=substr($num,-4,4);<br />$_SESSION['captcha'] = $num; // 把驗證碼寫入session<br />$nowimage=imagecreate(100,30);<br />imagecolorallocate($nowimage,240,240,240);<br />for($i=0;$i<strlen($num);$i++){<br />$font=mt_rand(3,5);<br />$x=mt_rand(1,8)+100*$i/4;<br />$y=mt_rand(1,50/4);<br />$color=imagecolorallocate($nowimage,rand(0,150),rand(0,150),rand(0,150));<br />imagestring($nowimage,$font,$x,$y,$num[$i],$color);<br />}<br />for($i=0;$i<200;$i++){<br />$randcolor=imagecolorallocate($nowimage,rand(200,255),rand(200,255),rand(200,255));<br />imagesetpixel($nowimage,rand()%70,rand()%20,$randcolor);<br />}<br />header("content-type:image/png");<br />imagepng($nowimage);<br />imagedestroy($nowimage);<br />?><br />