栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

php之验证码

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

php之验证码

header("Content-type: image/png");

gd_info();

$num=5;//生成验证码的字母个数

$type=2;//验证码的类型,0表示只有数字,1表示数字和小写字母,2表示数字和大写字母

$str=getCode($num,$type);

$width=$num*20;

$hight=30;

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

 

$color=imagecolorallocate($im,100,100,100);

$bg = imagecolorallocate($im,255,2,255);

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

 

###添加干扰点

for($i=0;$i<200;$i++){

        imagesetpixel($im,rand(0,$width),rand(0,$hight),$color);

}

  

###添加干扰线

for($i=0;$i<5;$i++){

        imageline($im,rand(0,$width),rand(0,$hight),rand(0,$width),rand(0,$hight),$color);

}

 

####在画布上画字符

for($i=0;$i<$num;$i++){

        imagechar($im,1000,5+(18*$i),8,$str[$i],$color);//图像源,字体大小,倾斜角度(0为不倾斜),起始x坐标,起始y坐标,颜色,字体文件,内容

}

 

//ob_clean();//清除缓冲区内

 

imagepng($im);

imagedestroy($im);

 

function getCode($num,$type)

{

        $content="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

        $t=array(9,35,strlen($content)-1);

        $c="";

        for($i=0;$i<$num;$i++)

        {

                $c.=$content[rand(0,$t[$type])];

        }

        return $c;

}

?>

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/230265.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号