PHP实现的验证码生成类分享
发表于:2024-10-19 作者:千家信息网编辑
千家信息网最后更新 2024年10月19日,本篇内容介绍了"PHP实现的验证码生成类分享"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!其中类成员
千家信息网最后更新 2024年10月19日PHP实现的验证码生成类分享
本篇内容介绍了"PHP实现的验证码生成类分享"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
其中类成员codestr是生成的验证码字符串:
width = $num*20; $this->height = $height; $this->num = $num; $this->imgType = $imgType; $this->Type = $Type; $this->codestr = $this->codestr(); $this->zuhe(); } // 2. 定义随机获取字符串函数 private function codestr(){ switch($this->Type){ case 1: // 类型为1 获取1-9随机数 $str = implode("",array_rand(range(0,9),$this->num)); break; case 2: // 类型为2 获取a-z随机小写字母 $str = implode("",array_rand(array_flip(range(a,z)),$this->num)); break; case 3: // 类型为3 获取数字,小写字母,大写字母 混合 for($i=0;$i<$this->num;$i++){ $m = rand(0,2); switch($m){ case 0: $o = rand(48,57); break; case 1: $o = rand(65,90); break; case 2: $o = rand(97,122); break; } $str .= sprintf("%c",$o); } break; } return $str; } // 3. 初始化画布图像资源 private function Hb(){ $this->hb = imagecreatetruecolor($this->width,$this->height); } // 4. 生成背景颜色 private function Bg(){ return imagecolorallocate($this->hb,rand(130,250),rand(130,250),rand(130,250)); } // 5. 生成字体颜色 private function Font(){ return imagecolorallocate($this->hb,rand(0,100),rand(0,100),rand(0,100)); } // 6. 填充背景颜色 private function BgColor(){ imagefilledrectangle($this->hb,0,0,$this->width,$this->height,$this->Bg()); } // 7. 干扰点 private function ganrao(){ $sum=floor(($this->width)*($this->height)/3); for($i=0;$i<$sum;$i++){ imagesetpixel($this->hb,rand(0,$this->width),rand(0,$this->height),$this->Bg()); } } // 8. 随机直线 弧线 private function huxian(){ for($i=0;$i<$this->num;$i++){ imageArc($this->hb,rand(0,$this->width),rand(0,$this->height),rand(0,$this->width),rand(0,$this->height),rand(0,360),rand(0,360),$this->Bg()); } } // 9. 写字 private function xiezi(){ for($i=0;$i<$this->num;$i++){ $x=ceil($this->width/$this->num)*$i; $y=rand(1,$this->height-15); imagechar($this->hb,5,$x+4,$y,$this->codestr[$i],$this->Font()); } } // 10. 输出 private function OutImg(){ $shuchu="image".$this->imgType; $header="Content-type:image/".$this->imgType; if(function_exists($shuchu)){ header($header); $shuchu($this->hb); }else{ exit("GD库没有此类图像"); } } // 11. 拼装 private function zuhe(){ $this->Hb(); $this->BgColor(); $this->ganrao(); $this->huxian(); $this->xiezi(); $this->OutImg(); } public function getCodeStr(){ return $this->codestr; }}?>
"PHP实现的验证码生成类分享"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
生成
验证
字母
类型
颜色
内容
图像
字符
字符串
小写
更多
知识
背景
输出
实用
学有所成
接下来
函数
困境
大写
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
加强网络安全保障建设
网络信息交流与网络安全
包头网络安全工程师招聘
如何查找数据库是否存在
软件开发与系统开发的区别
软件开发项目解除合同的条件
数据库配表
泰拉瑞亚 数据库
安桌im软件开发源
徐州品牌软件开发活动方案
数据库系统概论第六章问题讨论
安次区网络安全学习宣传活动
武汉的安全接入服务器地址
软件开发下的各个部门
实体服务器和云服务器
数据库中查找列名
怎样知道局域网服务器的电脑名
银行数据库技术
安卓 嵌入式数据库
棒的眼镜行业软件开发
数据库底层操作类
藏宝阁服务器时间校准
华为认证数据库工程师费用
百度实时路况来源于网络技术
利用云服务器打网游
数据库安装之后可以安软件吗
农行云音箱连接服务器时断时连
服务器cpu温度异常高的原因
网络安全技术监督
流放之路 鲁莽防御数据库