当前位置:首页 > 网站建设 > 正文内容

帝国cms更换漂亮美观的图形验证码

小熊6年前 (2018-03-30)网站建设6225

老威在SEO这一行做了快两年了,使用帝国cms大概一年半了,之前做的留言反馈都没加过验证码,容易被恶意留言,最近新做的一套网站要用到这个功能,觉得帝国cms的图形验证码有点扎眼,就顺手在重新写了下,外观比之前漂亮,同时使用弧线和直线,增强了干扰能力;双击图片可以不刷新页面更换验证码,默认的需要刷新页面。

帝国cms更换美观的图形验证码

使用方法:

1.将e文件直接复制到网站根目录;

2.开启 网站后台->系统参数->用户设置->会员登陆验证码和会员注册验证码;

3.不要设置 网站后台->系统参数->基本属性->验证码配色 保持最初默认值即可;

4.(可选)设置完后,认证码图片会比input输入框高可以用下面代码替换 ,同时用onclick不刷新页面更换验证码,兼容帝国7.0、7.2以及7.5版本。

模版->动态页面模版管理->会员登录页面

源代码:<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>

代码下载:链接:https://pan.baidu.com/s/1xeU_LzSlk3CVuL9Fh41SCg 密码:nzv0

贴出源代码供学习交流:

<?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);
?>


扫描二维码推送至手机访问。

版权声明:本文由小熊SEO发布,如需转载请注明出处。

本文链接:http://www.lwseo.cn/wzjs/72.html

分享给朋友:

相关文章

帝国cms列表页怎么调用关键字tag标签

帝国cms列表页怎么调用关键字tag标签

有很多朋友都在问帝国cms列表页怎么调用关键字tag,tag作为内链手法,对于SEO有一定的好处,下面老威就实例讲述一下帝国cms列表页面调用关键字tag标签的方法,分享给大家参考。具体实现方法如下:...

帝国cms搜索模版支持灵动标签调用的方法

帝国cms搜索模版支持灵动标签调用的方法

帝国CMS搜索模板不支持动态标签调用,从7.0到7.2再到刚发布的7.5,帝国官方团队始终没解决这个问题,这很不方便,但是帝国的强大可以让我们忽略这个问题,今天老威就把这个bug的解决方法说一下。第一...

帝国cms栏目页随机调用当前栏目内容

帝国cms栏目页随机调用当前栏目内容

老威做SEO教程也有段时间了,这期间也接触了大大小小的各种cms,其中还是帝国cms跟dedecms最深得我意,要是玩windows+iis环境的话,aspcms也是个很好的选择。在用帝国cms做站的...

帝国cms信息反馈表单怎么做

帝国cms信息反馈表单怎么做

帝国cms自带的信息反馈功能,不仅可以实现留言功能,还可以实现像在线报名、反馈这样的功能,所以说还是很强大的,它的原理是通过input获取数据库的表id,然后通过表单来提取数据,下面老威就把表单的制作...

帝国CMS怎么随机调用栏目【SEO养站手法】

帝国CMS怎么随机调用栏目【SEO养站手法】

我们经常看到有一些站做了全国很多的地区栏目,他们的栏目也能够互相循环,有利于蜘蛛的爬取,但是帝国CMS怎么来搞呢?之前老威讲过帝国CMS随机调用内容,有利于蜘蛛每次来抓取都能抓取到不同的信息,今天基于...

帝国cms调用当前产品的相关数据(可用来调用相关案例)

帝国cms调用当前产品的相关数据(可用来调用相关案例)

在用帝国cms做网站的时候,如果需要调用某数据的相关数据,需要通过新建字段给这个数据赋值,然后通过sql语句调用出来,比如机械行业中调用某个产品的相关案例,可以用到这个方法,具体如下:1.找到需要调用...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。