<br /><?<br />session_start();<br />function random($len)<br />{<br />$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";<br />mt_srand();<br />$strs="";<br />for($i=0;$i<$len;$i++){<br />$strs.=$srcstr[mt_rand(0,35)];<br />}<br />return strtoupper($strs);<br />}<br />$str=random(4); <br />$width = 50; <br />$height = 25; <br />@header("Content-Type:image/png");<br />$_SESSION["captcha"] = $str;<br />//echo $str;<br />$im=imagecreate($width,$height);<br />$back=imagecolorallocate($im,0xFF,0xFF,0xFF);<br />$pix=imagecolorallocate($im,187,230,247);<br />$font=imagecolorallocate($im,41,163,238);<br />mt_srand();<br />for($i=0;$i<1000;$i++)<br />{<br />imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);<br />}<br />imagestring($im, 5, 7, 5,$str, $font);<br />imagerectangle($im,0,0,$width-1,$height-1,$font);<br />imagepng($im);<br />imagedestroy($im);<br />$_SESSION["captcha"] = $str;<br />?><br /><br />
Copier après la connexion
<br /><img src="captcha.php" style="max-width:90%" style="max-width:90%" border="1" onclick= "this.src='captcha.php?act=captcha&'+Math.random()" style="cursor: pointer; vertical-align:middle" title="看不清?点击更换!" / alt="PHP 输出session 验证码与图片不同步,图片老是快一步,求解" ><br />
Copier après la connexion