帝国cms教程栏目,提供精品建站,仿站,二次开发,安装,标签使用等图文教程,帮助建设和管理好你的帝国cms站点。
帝国cms自带的验证码,实在是看不过去了,今天帝国模板之家小编给大家分享一个美化帝国cms验证码的代码,我们以用户登陆会员中心的验证码为例来讲解。具体操作如下:
1.开启会员登陆验证码,在网站后台->系统参数->用户设置->勾选会员登陆验证码和会员注册验证码;
2.设置不刷新页面更换验证码,在模板->动态页面模版管理->会员登录页面。
将
<img src="../../ShowKey/?v=login"/>
替换为
<img src="../../ShowKey/?v=login" onclick="javascript:this.src='../../ShowKey/?v=login&tm=+Math.random();'" style="vertical-align:middle"/> <span style="color:#666;vertical-align:bottom"> (点击图片更换)</span>
3.替换帝国默认的验证码代码,打开/e/ShowKey/index.php,全部替换为如下代码:
<?php
require('../class/connect.php');
//取得随机数
function domake_password($pw_length){
global $public_r;
if($public_r['keytog']==1)//字母
{
$low_ascii_bound=65;
$upper_ascii_bound=90;
$notuse=array(91);
}
elseif($public_r['keytog']==2)//数字+字母
{
$low_ascii_bound=50;
$upper_ascii_bound=90;
$notuse=array(58,59,60,61,62,63,64,73,79);
}
else//数字
{
$low_ascii_bound=48;
$upper_ascii_bound=57;
$notuse=array(58);
}
while($i<$pw_length)
{
mt_srand((double)microtime()*1000000);
$randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
if(!in_array($randnum,$notuse))
{
$password1=$password1.chr($randnum);
$i++;
}
}
return $password1;
}
//返回颜色
function ReturnShowKeyColor($img){
global $public_r;
//背景色
if($public_r['keybgcolor'])
{
$bgcr=ToReturnRGB($public_r['keybgcolor']);
$r['bgcolor']=imagecolorallocate($img,$bgcr[0],$bgcr[1],$bgcr[2]);
}
else
{
$r['bgcolor']=imagecolorallocate($img,245,rand(225,255),225);
}
//文字色
if($public_r['keyfontcolor'])
{
$fcr=ToReturnRGB($public_r['keyfontcolor']);
$r['fontcolor']=ImageColorAllocate($img,$fcr[0],$fcr[1],$fcr[2]);
}
else
{
$r['fontcolor']=ImageColorAllocate($img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
}
//干扰色
if($public_r['keydistcolor'])
{
$dcr=ToReturnRGB($public_r['keydistcolor']);
$r['distcolor']=ImageColorAllocate($img,$dcr[0],$dcr[1],$dcr[2]);
}
else
{
$r['distcolor']=ImageColorAllocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
}
return $r;
}
//显示验证码
function ShowKey($v){
$vname=ecmsReturnKeyVarname($v);
$key=strtolower(domake_password(4));
ecmsSetShowKey($vname,$key);
//是否支持gd库
if (function_exists("imagegif"))
{
header("Content-type: image/gif");
$img=imagecreate(80,26);
$colorr=ReturnShowKeyColor($img);
$bgcolor=$colorr['bgcolor'];
$fontcolor=$colorr['fontcolor'];
$distcolor=$colorr['distcolor'];
imagefill($img,0,0,$bgcolor);
for($i=0;$i<90;$i++) //加入干扰象素
{
imagesetpixel($img,rand()%70,rand()%30,$distcolor);
}
for($i=0;$i<8;$i++){//加入干扰弧线
imagearc ($img,rand(0,360),rand(0,360),rand(200,350),rand(200,360),10,10,imagecolorallocate($img, rand(0,225), rand(0,225),rand(0,225)));
}
for($i=0;$i<4;$i++){//加入干扰直线
imageline ($img,rand(0,2),rand(0,27),rand(80,80),rand(1,28),imagecolorallocate($img, mt_rand(0,156),mt_rand(0,156),mt_rand(0,156)));
}
for($i=0;$i<4;$i++){
$charcolor=imagecolorallocate($img, mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext ($img,rand(12,16),rand(-30,30),$i*20+2,rand(16,22),$charcolor,"STENCIL.TTF",$key[$i]);
}
imagegif($img);
imagedestroy($img);
}
elseif(function_exists("imagejpeg"))
{
header ("Content-type: image/jpeg");
$img=imagecreate(80,26);
$colorr=ReturnShowKeyColor($img);
$bgcolor=$colorr['bgcolor'];
$fontcolor=$colorr['fontcolor'];
$distcolor=$colorr['distcolor'];
imagefill($img,0,0,$bgcolor);
for($i=0;$i<90;$i++) //加入干扰象素
{
imagesetpixel($img,rand()%70,rand()%30,$distcolor);
}
for($i=0;$i<8;$i++){//加入干扰弧线
imagearc ($img,rand(0,360),rand(0,360),rand(200,350),rand(200,360),10,10,imagecolorallocate($img, rand(0,225), rand(0,225),rand(0,225)));
}
for($i=0;$i<4;$i++){//加入干扰直线
imageline ($img,rand(0,2),rand(0,27),rand(80,80),rand(1,28),imagecolorallocate($img, mt_rand(0,156),mt_rand(0,156),mt_rand(0,156)));
}
for($i=0;$i<4;$i++){
$charcolor=imagecolorallocate($img, mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext ($img,rand(12,16),rand(-30,30),$i*20+2,rand(16,22),$charcolor,"STENCIL.TTF",$key[$i]);
}
imagejpeg($img);
imagedestroy($img);
}
elseif (function_exists("imagepng"))
{
header ("Content-type: image/png");
$img=imagecreate(80,26);
$colorr=ReturnShowKeyColor($img);
$bgcolor=$colorr['bgcolor'];
$fontcolor=$colorr['fontcolor'];
$distcolor=$colorr['distcolor'];
imagefill($img,0,0,$bgcolor);
for($i=0;$i<90;$i++) //加入干扰象素
{
imagesetpixel($img,rand()%70,rand()%30,$distcolor);
}
for($i=0;$i<8;$i++){//加入干扰弧线
imagearc ($img,rand(0,360),rand(0,360),rand(200,350),rand(200,360),10,10,imagecolorallocate($img, rand(0,225), rand(0,225),rand(0,225)));
}
for($i=0;$i<4;$i++){//加入干扰直线
imageline ($img,rand(0,2),rand(0,27),rand(80,80),rand(1,28),imagecolorallocate($img, mt_rand(0,156),mt_rand(0,156),mt_rand(0,156)));
}
for($i=0;$i<4;$i++){
$charcolor=imagecolorallocate($img, mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext ($img,rand(12,16),rand(-30,30),$i*20+2,rand(16,22),$charcolor,"STENCIL.TTF",$key[$i]);
}
imagepng($img);
imagedestroy($img);
}
elseif (function_exists("imagewbmp"))
{
header ("Content-type: image/vnd.wap.wbmp");
$img=imagecreate(80,26);
$colorr=ReturnShowKeyColor($img);
$bgcolor=$colorr['bgcolor'];
$fontcolor=$colorr['fontcolor'];
$distcolor=$colorr['distcolor'];
imagefill($img,0,0,$bgcolor);
for($i=0;$i<90;$i++) //加入干扰象素
{
imagesetpixel($img,rand()%70,rand()%30,$distcolor);
}
for($i=0;$i<8;$i++){//加入干扰弧线
imagearc ($img,rand(0,360),rand(0,360),rand(200,350),rand(200,360),10,10,imagecolorallocate($img, rand(0,225), rand(0,225),rand(0,225)));
}
for($i=0;$i<4;$i++){//加入干扰直线
imageline ($img,rand(0,2),rand(0,27),rand(80,80),rand(1,28),imagecolorallocate($img, mt_rand(0,156),mt_rand(0,156),mt_rand(0,156)));
}
for($i=0;$i<4;$i++){
$charcolor=imagecolorallocate($img, mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext ($img,rand(12,16),rand(-30,30),$i*20+2,rand(16,22),$charcolor,"STENCIL.TTF",$key[$i]);
}
imagewbmp($img);
imagedestroy($img);
}
else
{
ecmsSetShowKey($vname,'ecms');
echo ReadFiletext("../data/images/ecms.gif");
}
}
//返回变量名
function ecmsReturnKeyVarname($v){
if($v=='login')//登陆
{
$name='checkloginkey';
}
elseif($v=='reg')//注册
{
$name='checkregkey';
}
elseif($v=='info')//信息
{
$name='checkinfokey';
}
elseif($v=='spacefb')//空间反馈
{
$name='checkspacefbkey';
}
elseif($v=='spacegb')//空间留言
{
$name='checkspacegbkey';
}
elseif($v=='gbook')//留言
{
$name='checkgbookkey';
}
elseif($v=='feedback')//反馈
{
$name='checkfeedbackkey';
}
elseif($v=='getpassword')//取回密码
{
$name='checkgetpasskey';
}
elseif($v=='regsend')//重发激活邮件
{
$name='checkregsendkey';
}
else//评论pl
{
$name='checkplkey';
}
return $name;
}
$v=$_GET['v'];
ShowKey($v);
?>
4.上传字体文件到/e/ShowKey/目录下 ,字体文件登录后在文章底部下载。
整合后效果图如下:
推荐教程:帝国CMS教程
以上就是帝国cms验证码美化代码,更多相关内容请关注帝国模板之家。
转载请注明来源:帝国cms验证码美化代码
本文永久链接地址:https://www.moyouyouw.cn/code/558.html
郑重声明:本站所有主题/文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除,谢谢!我们不承担任何技术及版权问题,且不对任何资源负法律责任。
售价: 400 10 ℃ 0 评论
售价: 300 24 ℃ 0 评论
售价: 300 10 ℃ 0 评论
已有 位小伙伴发表了看法
欢迎 你 发表评论