PHP生成雪花背景的验证码
2017-01-02 19:12
302 查看
<php
header("Content-type: image/png");
$img_height=80;
$img_width=22;
$im = imagecreate($img_height,$img_width);
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
for ($i=1; $i<=100; $i++) {
imagestring($im,1,mt_rand(1,$img_height),mt_rand(1,$img_width),"*",imagecolorallocate($im,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));
}
//$str=mt_rand(1000,9000);
$acceptedChars = '1234567890abcdefghijklmnopqrstuvwxyz';
$max = strlen($acceptedChars)-1;
$str="";
for($i=0; $i < 4; $i++) {
$str .= $acceptedChars{mt_rand(0, $max)};
$str.=" ";
}
imagestring($im, 5,8,3,$str, $text_color);
imagepng($im);
imagedestroy($im);
?>