解决Yii自带的验证码不随页面刷新自动刷新的问题
2014-09-17 15:50
260 查看
如何添加验证码,这里就不再多说了,网上有很多的资料。自己按照网上的资料搜索添加即可,
验证码添加好之后,会发现,刷新页面Yii的验证码并不会自动刷新,目前解决这个的办法有三种:
一、修改源码CCaptchaAction.php的run方法,不推荐
二、写一个js,在页面刷新的时候调用js自动点击验证码图片实现刷新,感觉有点...,太依赖js了不太好吧
三、在components文件夹下新建一个文件Captcha.php
添加如下代码,重写run方法:
class Captcha extends CCaptchaAction{
//重写run方法,使得验证码在页面刷新时刷新
public function run(){
if (isset($_GET[self::REFRESH_GET_VAR])){
$code = $this->getVerifyCode(true);
echo CJSON::encode(array(
'hash1' => $this->generateValidationHash($code),
'hash2' => $this->generateValidationHash(strtolower($code)),
'url' => $this->getController()->createUrl($this->getId(), array('v' => uniqid())),
));
}else {
$this->renderImage($this->getVerifyCode(true));
Yii::app()->end();
}
}
}
之后修改controller中class为captcha即可,代码如下
public function actions(){
return array(
'captcha'=>array(
'class'=>'Captcha',
'backColor'=>0xFFFFFF,
'maxLength'=>'4', // 最多生成几个字符
'minLength'=>'4', // 最少生成几个字符
'height'=>'40',
'width'=>'230',
'transparent'=>true, //显示为透明
'testLimit' => 0, //限制相同验证码出现的次数,0为不限制
),
);
}
现在再去刷新一下页面试试看,验证码是不是随页面刷新而刷新了呢
验证码添加好之后,会发现,刷新页面Yii的验证码并不会自动刷新,目前解决这个的办法有三种:
一、修改源码CCaptchaAction.php的run方法,不推荐
二、写一个js,在页面刷新的时候调用js自动点击验证码图片实现刷新,感觉有点...,太依赖js了不太好吧
三、在components文件夹下新建一个文件Captcha.php
添加如下代码,重写run方法:
class Captcha extends CCaptchaAction{
//重写run方法,使得验证码在页面刷新时刷新
public function run(){
if (isset($_GET[self::REFRESH_GET_VAR])){
$code = $this->getVerifyCode(true);
echo CJSON::encode(array(
'hash1' => $this->generateValidationHash($code),
'hash2' => $this->generateValidationHash(strtolower($code)),
'url' => $this->getController()->createUrl($this->getId(), array('v' => uniqid())),
));
}else {
$this->renderImage($this->getVerifyCode(true));
Yii::app()->end();
}
}
}
之后修改controller中class为captcha即可,代码如下
public function actions(){
return array(
'captcha'=>array(
'class'=>'Captcha',
'backColor'=>0xFFFFFF,
'maxLength'=>'4', // 最多生成几个字符
'minLength'=>'4', // 最少生成几个字符
'height'=>'40',
'width'=>'230',
'transparent'=>true, //显示为透明
'testLimit' => 0, //限制相同验证码出现的次数,0为不限制
),
);
}
现在再去刷新一下页面试试看,验证码是不是随页面刷新而刷新了呢
相关文章推荐
- 解决Yii自带的验证码不随页面刷新自动刷新的问题
- yii自带验证码,解决刷新页面验证码不刷新问题
- 如何解决win10自带microsoft edge出现打不开标签页、打开标签页后闪退、新建标签页后卡死、页面跳转后打不开新页面并且原页面自己重复刷新等问题
- YII framework CCaptchaAction 解决YII验证码不更新的刷新问题
- 解决Button自动刷新页面的问题
- IE7和IE8下验证码自动刷新失败的问题及解决方法
- js生效后页面自动刷新的问题(js控制button,生效效果闪一下消失)解决
- ShowModelessDialog打开页面自动刷新问题解决方法【原】
- 解决刷新页面造成的数据重复提交问题
- asp.net 2.0 中怎么解决页面的刷新问题
- JavaScript页面刷新与弹出窗口问题解决方法
- 某一框架页面使整个框架页面刷新问题的解决办法!
- 用脚本解决ASP.NET页面刷新问题
- 解决JavaScript页面刷新与弹出窗口问题
- JavaScript页面刷新与弹出窗口问题解决方法
- 用脚本解决ASP.NET页面刷新问题
- 解决因页面刷新而导致重复操作的问题
- html页面自动刷新问题
- 解决刷新页面造成的数据重复提交问题
- 解决刷新页面造成的数据重复提交问题