您好,欢迎访问一九零五行业门户网

在thinkphp中使用phpcms的验证码

thinkphp原装的验证码感觉不太好看,用phpcms的时候,看到他们的验证码挺不错的,拿过来用一下。
主要代码如下:
config.php中'配置值'
    /**
     * verify常量设置
     */
        //'verify_width'    =>    '130',
        //验证码的宽度
        'verify_width'    =>    130,
//验证码的高
        'verify_height'    =>    50,
//设置随机生成因子
        'verify_charset'    =>    'abcdefghkmnprstuvwyzabcdefghklmnprstuvwyz23456789',
//设置背景色
        'verify_background'    =>    '#edf7ff',
//生成验证码字符数
        'verify_code_len'    =>    4,
//字体大小
        'verify_font_size'    =>    20,
);
?>indexaction.class.php方法中的代码如下display();
    }
public function verify(){
        import('@.class.verify.verify');
        $verify = new verify();
$code_len = c('verify_code_len');
        $font_size = c('verify_font_size');
        $width = c('verify_width');
        $height = c('verify_height');
        $font_size = c('verify_font_size');
        $font_size = c('verify_font_size');
        $font_size = c('verify_font_size');
//echo $code_len;die;
        if (isset($code_len) && intval($code_len)) $verify->code_len = intval($code_len);
        if ($verify->code_len > 8 || $verify->code_len             $verify->code_len = 4;
        }
        if (isset($font_size) && intval($font_size)) $verify->font_size = intval($font_size);
        if (isset($width) && intval($width)) $verify->width = intval($width);
        if ($verify->width             $verify->width = 130;
        }
if (isset($height) && intval($height)) $verify->height = intval($height);
        if ($verify->height             $verify->height = 50;
        }
        $max_width = $verify->code_len * 28;
        $max_height = $verify->font_size * 2;
        if($verify->width > $max_width) $verify->width = $max_width;
        if($verify->height > $max_height) $verify->height = $max_height;
        $verify->doimage();
        session('code',$verify->get_code());
}
public function check(){
        $verify = strtolower($_get['verify']);
        $code = $_session['code'];
        if ($verify == $code){
            $this->success('你太厉害了,竟然把验证码写对了!',u('index/index'));
        }else{
            $this->error('你个大笨蛋,竟然连验证码都写不对,还能干啥!');
        }
    }
}自从用了thinkphp高级版本出现php环境不支持后,一直在使用thinkphp 3.1.3,所以我的代码是基于这个版本的。如果在其他版本上有需求,请自行修改,全部代码会在附件中分享。
在thinkphp中使用phpcms的验证码.zip ( 1.57 mb 下载:28 次 )
ad:真正免费,域名+虚机+企业邮箱=0元
其它类似信息

推荐信息