首页建站经验 php 生成复杂验证码图片

php 生成复杂验证码图片

php 生成复杂验证码图片代码如下:function image3($length=4,$type='png',$width=180,$height=60,$fontface='fpnf.ttf',$verifyName='verify') {$code = $this->rand_strin…

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);

}

 

 

本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/jianzhan/jingyan/17470.html
上一篇帝国网站管理系统后台界面管理
下一篇 PHP读取目录下所有文件,并通过ajax返回json格式的数据
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部