<?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,所以我的代码是基于这个版本的。如果在其他版本上有需求,请自行修改,全部代码会在附件中分享。附件 在thinkphp中使用phpcms的验证码.zip ( 1.57 MB 下载:32 次 )
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。