A5下载站:努力做内容最丰富最安全的下载站! 网站地图最新更新下载排行专题软件发布

热门软件

地铁跑酷

冒险迷岛

全民迷宫

连连消大作战

小河狸创客

阿里健康医鹿

支付宝app

番薯小说

MOMO陌陌

虾米音乐app

位置导航:A5下载 > 源码技巧 > 父类数据

php 生成复杂验证码图片

时间:2015-06-09 15:30来源:未知作者:sa浏览:110
php 生成复杂验证码图片 代码如下: function image3($length=4,$type='png',$width=180,$height=60,$fontface='fpnf.ttf',$verifyName='verify') { $code = $this-rand_string($length,4); $width = ($length*25)$width?$length*25:$width; $authCode = new……

php 生成复杂验证码图片

代码如下:

function image3($length=4,$type='png',$width=180,$height=60,$fontface='fpnf.ttf',$verifyName='verify') {

$code = $this->rand_string($length,4);

$width = ($length*25)>$width?$length*25:$width;

$authCode = new Zend_Session_Namespace('Auth_Code');

$authCode->imagecode = $randval;

$im=imagecreatetruecolor($width,$height);

$borderColor = imagecolorallocate($im, 100, 100, 100); //边框色

$bkcolor=imagecolorallocate($im,250,250,250);

imagefill($im,0,0,$bkcolor);

@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);

// 干扰

for($i=0;$i<15;$i++){//开源代码phpfensi.com
$fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagearc($im,mt_rand(-10,$width),mt_rand(-10,$height),mt_rand(30,300),mt_rand(20,200),55,44,$fontcolor);

}

for($i=0;$i<255;$i++){
$fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$fontcolor);

}

if(!is_file($fontface)) {

$fontface = dirname(__FILE__)."/".$fontface;

}

for($i=0;$i<$length;$i++){
$fontcolor=imagecolorallocate($im,mt_rand(0,120),mt_rand(0,120),mt_rand(0,120)); //这样保证随机出来的颜色较深。

$codex= substr($code,$i,1);
imagettftext($im,mt_rand(16,20),mt_rand(-60,60),40*$i+20,mt_rand(30,35),$fontcolor,$fontface,$codex);

}

$this->output($im,$type);

}

function output($im,$type='png')

{

header("Content-type: image/".$type);

$ImageFun='Image'.$type;

$ImageFun($im);

imagedestroy($im);

}