GD库 验证码函数
来源:互联网 发布:矩阵潜袭扩展和循环 编辑:程序博客网 时间:2024/06/05 20:43
慕课网后 端开发PHP教程-->PHP进阶篇--GD库图像处理-->http://www.imooc.com/learn/701-->2-5 验证码函数的封装及测试
<?phpheader("content-type:text/html;charset=utf-8");function getVerify($type=3,$length=6,$codeName='code',$pixel=100,$line=0,$arc=0,$width=200,$height=50,$fontFile='fonts/7.ttf'){//创建画布$image=imagecreatetruecolor($width,$height);//创建颜色$white=imagecolorallocate($image,255,255,255);//创建填充矩形imagefilledrectangle($image,0,0,$width,$height,$white);function getRandColor($image){return imagecolorallocate($image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));}/**默认4位数字* 1-数字 * 2-字母 *3-数字+字母 * 汉字*/switch($type){case 1: //数字$string=str_shuffle(join('',array_rand(range(0,9),$length)));break;case 2: //字母$string=str_shuffle(join('',array_rand(array_flip(array_merge(range('a','z'),range('A','Z'))),$length)));break;case 3: //数字+字母$string=str_shuffle(join('',array_rand(array_flip(array_merge(range('a','z'),range('A','Z'),range(0,9))),$length)));break;case 4: //汉字$str="勇,担,金,砖,责,任,维,护,世,界,和,平,宁,国,家,要,联,合,宪,章,宗,旨,原,则,以,及,际,关,系,基,本,准,坚,定,多,边,主,义,推,动,民,化,反,对,霸,权,强,政,治,倡,导,共,同,综,作,可,持,续,的,安,全,观,建,设,性,参,与,地,缘,热,点,问,题,解,决,进,程,发,挥,应,有,用";$arr=explode(',',$str);$string=str_shuffle(join('',array_rand(array_flip($arr),$length)));break;default: exit('非法操作');break;}session_start();$_SESSION[$codeName]=$string;for($i=0;$i<$length;$i++){$size=mt_rand(20,28);$angle=mt_rand(-15,15);$x=ceil($width/$length)*$i+imagefontwidth($size);//50+30*$i;$y=mt_rand($height/2,$height-imagefontheight($size));//30;$color=getRandColor($image);$text=mb_substr($string,$i,1,'utf-8');imagettftext($image,$size,$angle,$x,$y,$color,$fontFile,$text);}///添加干扰点if($pixel>0){for($i=1;$i<=$pixel;$i++){imagesetpixel($image,mt_rand(0,$width),mt_rand(0,$height),getRandColor($image));}}//添加干扰线if($line>0){for($i=1;$i<=$line;$i++){imageline($image,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),getRandColor($image));}}//添加圆弧if($arc>0){for($i=1;$i<=$arc;$i++){imagearc($image,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width/2),mt_rand(0,$height/2),mt_rand(0,360),mt_rand(0,360),getRandColor($image));}}//告诉浏览器以图片的形式显示header("content-type:image/jpeg");//imagejpeg($image) 输出图像imagejpeg($image);//销毁资源imagedestroy($image);}getVerify();?>
阅读全文
0 0
- GD库 验证码函数
- php 使用GD库生成验证码
- php 使用GD库生成验证码
- php 基于GD库验证码
- php GD库生成验证码
- php 简易验证码(GD库)
- php通过GD库实现验证码
- php GD库画图 验证码
- 使用GD库制作验证码
- php使用GD库生成验证码
- GD库 验证码类的封装
- GD验证码练习
- 验证码 GD FREETYPE
- GD验证码
- GD 验证码类
- 应用PHP GD库中图像处理函数制作验证码
- 运用php GD库的图像函数制作登录验证码图片
- php验证码 GD库生成验证码
- 【DB】MySQL傻瓜安装,超简单
- 推荐五款管理工具(思维导图)
- 浏览器中的JS解析器 作用域 作用域链 全局作用域 局部作用域
- 谷歌浏览器network请求时间分析!
- qt 计算器实现(中缀转后缀,后缀计算)
- GD库 验证码函数
- 翻译连载 | JavaScript轻量级函数式编程-第6章:值的不可变性 |《你不知道的JS》姊妹篇
- 机房收费系统之 多步 OLE DB 操作产生错误
- 实习面试题
- zabbix系列(二)zabbix3.0.7远程重启haproxy
- 输入3个整数,输出其最大值
- 什么是Gradle
- BZOJ 1854 [Scoi 2010] 二分图 解题报告
- 安全科普:理解SSL(https)中的对称加密与非对称加密