代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PHP
】
PHP验证类
作者:
summer-K
/ 发布于
2012/3/6
/
596
<div><?php</div> <div>class checkcode</div> <div>{</div> <div> //图像句柄</div> <div> private $img;</div> <div> //画布宽</div> <div> public $width=85;</div> <div> //画布搞</div> <div> public $height=25;</div> <div> //背景颜色</div> <div> public $bg_color = "#DCDCDC";</div> <div> //验证码</div> <div> public $code;</div> <div> //验证码库</div> <div> public $code_str = "sadhadh1ui2y9822ur2r9283r9rqdadqe12423reffqadfja09sdf0rpafashdfqwer98fqortFP89EDFIOQHFWEFTrgwfOGUsgdfKHAEFUHuqGR";</div> <div> //验证码长度</div> <div> public $code_len = 4;</div> <div> //验证码字体</div> <div> public $font;</div> <div> //字体大小</div> <div> public $font_size = 16;</div> <div> //字体颜色</div> <div> public $font_color = "#ffffff";</div> <div> </div> <div> /*</div> <div> * 构造函数</div> <div> */</div> <div> public function __construct()</div> <div> {</div> <div> $this->font = "font".DIRECTORY_SEPARATOR."arial.ttf";</div> <div> } <div> /*</div> <div> *验证码生成函数</div> <div> */</div> <div> private function create_code()</div> <div> {</div> <div> $code=" ";</div> <div> for($i=0;$i<$this->code_len;$i++)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> {</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $code.=$this->code_str[mt_rand(0,strlen($this->code_str)-1)];</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> } <div><span class="Apple-tab-span" style="white-space:pre"> </span> $this->code = $code;</div> <div> } <div> /*</div> <div> *得到验证码</div> <div> */</div> <div> public function getcode()</div> <div> {</div> <div> return strtoupper($this->code);</div> <div> } <div> /*</div> <div> * 创建图画句柄</div> <div> */</div> <div> public function getimg()</div> <div> {</div> <div> $w = $this->width;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $h = $this->height;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $img = imagecreatetruecolor($w,$h);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $bg_color = imagecolorallocate($img,hexdec(substr($bg_color,1,2)),hexdec(substr($img,3,2)),hexdec(substr($img,5,2)));</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> imagefill($img,0,0,$bg_color);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $this->img = $img;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $this->create_font();</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $this->create_pix();</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $this->show_code();</div> <div> } <div> /*</div> <div> *创建字体</div> <div> */</div> <div> public function create_font()</div> <div> {</div> <div> $this->create_code();</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>$color= $this->font_color;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>$font_color = imagecolorallocate($this->img, hexdec(substr($color, 1,2)), hexdec(substr($color, 3,2)), hexdec(substr($color, 5,2)));</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> $x = $this->width/$this->code_len;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> for($i=0;$i<$this->code_len;$i++){</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> imagettftext($this->img, $this->font_size, mt_rand(-30, 30), $x*$i+mt_rand(3,6), mt_rand($this->height/1.2,$this->height-5), $font_color, $this->font, $this->code[$i]);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> } <div><span class="Apple-tab-span" style="white-space:pre"> </span> $this->font_color = $font_color;</div> <div> } <div> /*</div> <div> *写人干扰</div> <div> */</div> <div> private function create_pix()</div> <div> {</div> <div> $pix_color = $this->font_color;</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> for($i=0;$i<100;$i++)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> {</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> imagesetpixel($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),$pix_color);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> } <div><span class="Apple-tab-span" style="white-space:pre"> </span> for($j=0;$j<2;$j++)</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> {</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> imagesetthickness($this->img,mt_rand(2,4));</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$pix_color);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span> } <div> } <div> /*</div> <div> *显示代码</div> <div> */</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>private function show_code(){</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>header("Content-type:image/png");</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>imagepng($this->img);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>imagedestroy($this->img);</div> <div><span class="Apple-tab-span" style="white-space:pre"> </span>} <div>} <div>?></div>
试试其它关键字
验证类
同语言下
.
用net匹配并替换iOS标准的emoji表情符号
.
处理带Emoji表情的的字符串
.
获取微信昵称时 过滤特殊字符
.
通过判断上传文件的头字符来判断文件的类型
.
模拟百度URL加密解密算法
.
以太坊检查地址是否合法
.
实现crontab解析类
.
获取每个月的开始和结束时间
.
图片上传工具类
.
APP手机应用信息采集
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
summer-K
贡献的其它代码
(
1
)
.
PHP验证类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3