QQ群:282882201

阿里云搞活动,想要抓紧买:https://promotion.aliyun.com/ntms/act/qwbk.html?userCode=4hy76kwx
主要代码如下:
config.php中
<?php
return array(
//'配置项'=>'配置值'
/**
* 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方法中的代码如下<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$this->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 < 2) {
$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 <= 0) {
$verify->width = 130;
}
if (isset($height) && intval($height)) $verify->height = intval($height);
if ($verify->height <= 0) {
$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,所以我的代码是基于这个版本的。如果在其他版本上有需求,请自行修改,全部代码会在附件中分享。QQ群:282882201

阿里云搞活动,想要抓紧买:https://promotion.aliyun.com/ntms/act/qwbk.html?userCode=4hy76kwx
在thinkphp中使用phpcms的验证码.zip
( 1.57 MB 下载:32 次 )