-
public function valiCodeImage($valicode_name=valicode’)
-
{
-
$str = self::_random(5); //随机生成的字符串
-
$width = 60; //验证码图片的宽度
-
$height = 25; //验证码图片的高度
-
@header("Content-Type:image/png");
-
$im=imagecreate($width,$height);
-
//背景色
-
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
-
//模糊点颜色
-
$pix=imagecolorallocate($im,187,230,245);
-
//字体色
-
$font=imagecolorallocate($im,40,160,230);
-
//绘模糊作用的点
-
mt_srand();
-
for($i=0;$i<1000;$i++)
-
{
-
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
-
}
-
imagestring($im, 5, 7, 5,$str, $font);
-
imagerectangle($im,0,0,$width-1,$height-1,$font);
-
imagepng($im);
-
imagedestroy($im);
-
-
if( empty($valicode_name) ){
-
$valicode_name = valicode’;
-
}
-
$_SESSION[$valicode_name] = $str;
-
//echo $str;
-
}
-
private function _random($len) {
-
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-
mt_srand();
-
$strs="";
-
for($i=0;$i<$len;$i++){
-
$strs.=$srcstr[mt_rand(0,61)];
-
}
-
return $strs;
-
}
php生成图片验证码
- No comments yet.
- No trackbacks yet.
Recent Comments