<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 />
登入後複製