蝙蝠岛资源网 Design By www.hbtsch.com
现在好多网站使用的验证码非常容易被软件自动识别到,本文介绍了一种PHP生成复杂验证码加入倾斜,弦干扰线,黏贴,旋转等效果
常见的软件不容易自动识别的验证码做法有以下3种:
1、字体变型 (一般通过算法,进行扭曲)
2、字体黏贴 (这里面以qq验证码为代表了,目前网上还是很难找到,破解qq验证码的)
3、干扰线,噪点 (这种识别起来相当容易,很容易被程序自动化识别)
对于上面提到,第1,2 二种方法,在识别时候,是比较困难的。
具体实现代码:
<"#FFFFFF"; //背景色
var $TFonts = array("font.ttf");
var $TFontSize=array(17,20); //字体大小范围
var $TFontAngle=array(-20,20); //旋转角度
var $Chars = "0123456789"; //验证码范围(字母数字)
var $Code = array(); //验证码
var $Image = ""; //图形对象
var $FontColors=array('#f36161','#6bc146','#5368bd'); //字体颜色,红绿蓝
var $TPadden = 0.75;///字符间距,多少个字符
var $Txbase = 5;///x轴两边距离
var $Tybase =5 ;///y轴两边距离
var $TLine =true; ///画干扰线
public function RandRSI() ///生成验证码
{
$this->TFontAngle=range($this->TFontAngle[0],$this->TFontAngle[1]);
$this->TFontSize=range($this->TFontSize[0],$this->TFontSize[1]);
$arr=array();
$Chars=$this->Chars;
$TFontAngle=$this->TFontAngle;
$TFontSize=$this->TFontSize;
$FontColors=$this->FontColors;
$code="";
$font=dirname(__FILE__)."/font/".$this->TFonts[0];
$charlen=strlen($Chars)-1;
$anglelen=count($TFontAngle)-1; // 角度范围
$fontsizelen=count($TFontSize)-1; // 角度范围
$fontcolorlen=count($FontColors)-1; // 角度范围
for($i=0;$i<$this->Length;$i++) ///得到字符与颜色
{
$char=$Chars[rand(0,$charlen)]; ///得到字符
$angle=$TFontAngle[rand(0,$anglelen)]; ///旋转角度
$fontsize=$TFontSize[rand(0,$fontsizelen)]; ///字体大小
$fontcolor=$FontColors[rand(0,$fontcolorlen)]; ///字体大小
$bound=$this->_calculateTextBox($fontsize,$angle,$font,$char); ///得到范围
$arr[]=array($fontsize,$angle,$fontcolor,$char,$font,$bound); ///得到矩形框
$code.=$char;
}
$this->Code=$arr; //验证码
return $code;
}
public function Draw() ///画图
{
if(empty($this->Code)) $this->RandRSI();
$codes=$this->Code; ///用户验证码
$wh=$this->_getImageWH($codes);
$width=$wh[0];
$height=$wh[1]; ///高度
$this->Width=$width;
$this->Height=$height;
$this->Image = imageCreate( $width, $height );
$image=$this->Image;
$back = $this->_getColor2($this->_getColor( $this->BgColor)); ///背景颜色
imageFilledRectangle($image, 0, 0, $width, $height, $back); ///填充背景
$TPadden=$this->TPadden;
$basex=$this->Txbase;
$color=null;
foreach ($codes as $v) ///逐个画字符
{
$bound=$v[5];
$color=$this->_getColor2($this->_getColor($v[2]));
imagettftext($image, $v[0], $v[1], $basex, $bound['height'],$color , $v[4], $v[3]);
$basex=$basex+$bound['width']*$TPadden-$bound['left'];///计算下一个左边距
}
$this->TLine"Content-type: image/png");
imagepng( $image);
imagedestroy($image);
}
/**
*通过字体角度得到字体矩形宽度*
*
* @param int $font_size 字体尺寸
* @param float $font_angle 旋转角度
* @param string $font_file 字体文件路径
* @param string $text 写入字符
* @return array 返回长宽高
*/
private function _calculateTextBox($font_size, $font_angle, $font_file, $text) {
$box = imagettfbbox($font_size, $font_angle, $font_file, $text);
$min_x = min(array($box[0], $box[2], $box[4], $box[6]));
$max_x = max(array($box[0], $box[2], $box[4], $box[6]));
$min_y = min(array($box[1], $box[3], $box[5], $box[7]));
$max_y = max(array($box[1], $box[3], $box[5], $box[7]));
return array(
'left' => ($min_x >= -1) "htmlcode">
$rsi = new Utils_Caption();
$rsi->TFontSize=array(15,17);
$rsi->Width=50;
$rsi->Height=25;
$code = $rsi->RandRSI();
session_start();
$_SESSION["CHECKCODE"] = $code;
$rsi->Draw();
运行效果:
点击下载源码
大家可以修改代码中的相应数值达到自己需要的复杂度
蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com
暂无php生成复杂验证码(倾斜,正弦干扰线,黏贴,旋转)的评论...
更新日志
2025年10月29日
2025年10月29日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]



