thinkPHP中验证码的简单实现方法
发布时间:2020-12-14 14:06:51 所属栏目:大数据 来源:网络整理
导读:本篇章节讲解thinkPHP中验证码的简单实现方法。供大家参考研究具体如下: 运行效果图如下: 1.php端生成验证码函数 $width ? $length * 10 + 10 : $width; if ($type != 'gif' function_exists('imagecreatetruecolor')) { $im = imagecreatetruec
本篇章节讲解thinkPHP中验证码的简单实现方法。分享给大家供大家参考,具体如下: 运行效果图如下: 1.php端生成验证码函数 $width ? $length * 10 + 10 : $width;
if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
$im = imagecreatetruecolor($width,$height);
} else {
$im = imagecreate($width,$height);
}
$r = Array(225,255,223);
$g = Array(225,236,237,255);
$b = Array(225,166,125);
$key = mt_rand(0,3);
$backColor = imagecolorallocate($im,$r[$key],$g[$key],$b[$key]); //背景色(随机)
$borderColor = imagecolorallocate($im,100,100); //边框色
imagefilledrectangle($im,$width - 1,$height - 1,$backColor);
imagerectangle($im,$borderColor);
$stringColor = imagecolorallocate($im,mt_rand(0,200),120),120));
// 干扰
for ($i = 0; $i < 10; $i++) {
imagearc($im,mt_rand(-10,$width),$height),mt_rand(30,300),mt_rand(20,55,44,$stringColor);
}
for ($i = 0; $i < 25; $i++) {
imagesetpixel($im,$stringColor);
}
for ($i = 0; $i < $length; $i++) {
imagestring($im,5,$i * 10 + 5,mt_rand(1,8),$randval{$i},$stringColor);
}
Image::output($im,$type);
}
生成图片的同时,传入到session中。 2.页面端 直接src中调用。 点击触发改变。 3.后台验证,对比post字段与session中的验证码是否一致。 error('验证码错误!');
}
更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》。 希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |