ok
现在是,打开页面验证码就现实不了。
- ok 赞了回复
前台验证成功,表单提交就提示验证码错误;原因可能是ajax验证一次 致使验证码在session中已经变了 再提交就提示错误了 怎么解决?
- ok 收藏了教程解决Yii2中刷新网页时验证码不刷新的问题
我也发个吧
在PHP中public function actions() { return array( 'captcha' => array( 'class' => 'yii\captcha\CaptchaAction', 'maxLength' => 5, 'minLength' => 5, 'width'=>120, 'height'=>'27', ), ); }
这个大家都知道,在页面中我没用YII的form,而是自己写的表单
<input type="text" id="codeid" name="checkcode" class="form-control" placeholder="验证码"> <div class="input-group-addon" id="logincode"> <img src="/res/images/logincode.gif" id="code_img" alt="点击刷新"> </div>
且看JS部分
<script> $(function(){ $("#codeid").focus(function(){ $.get('<?php echo Yii::$app->urlManager->createUrl('site/captcha');?>?',{refresh:1},function(data){ evaldata=eval(data); $("#code_img").attr('src',evaldata.url); }); }); $("#code_img").click(function(){ $.get('<?php echo Yii::$app->urlManager->createUrl('site/captcha');?>',{refresh:1},function(data){ evaldata=eval(data); $("#code_img").attr('src',evaldata.url); }); }); }) </script>
我们通过向/site/captcha?refresh=1发送GET请求,得到的数据如下,
{"hash1":538,"hash2":538,"url":"/backend/web/site/captcha?v=56a8243edb9a8"}
很清楚的我们得到了一个新的验证码URL,
这里说下V,V是用PHP的uniqid()生成的一个唯一码
这个方法不用改YII的任何代码哦如果你在model里面进行两次验证码的验证那么你的验证就会通不过哦。
YII的验证码不论是生成的时候还是验证的时候都是通过了getVerifyCode,验证通过后会重新在生成一次验证码,所以在model里如果你调用了两次验证的话,就通不过哦
這个方法给力,直接在model的rules验证就添加参数验证就可以了,。但是我修改actions方法的captcha的大小就不生效了。
- ok 赞了评论
我也发个吧
在PHP中public function actions() { return array( 'captcha' => array( 'class' => 'yii\captcha\CaptchaAction', 'maxLength' => 5, 'minLength' => 5, 'width'=>120, 'height'=>'27', ), ); }
这个大家都知道,在页面中我没用YII的form,而是自己写的表单
<input type="text" id="codeid" name="checkcode" class="form-control" placeholder="验证码"> <div class="input-group-addon" id="logincode"> <img src="/res/images/logincode.gif" id="code_img" alt="点击刷新"> </div>
且看JS部分
<script> $(function(){ $("#codeid").focus(function(){ $.get('<?php echo Yii::$app->urlManager->createUrl('site/captcha');?>?',{refresh:1},function(data){ evaldata=eval(data); $("#code_img").attr('src',evaldata.url); }); }); $("#code_img").click(function(){ $.get('<?php echo Yii::$app->urlManager->createUrl('site/captcha');?>',{refresh:1},function(data){ evaldata=eval(data); $("#code_img").attr('src',evaldata.url); }); }); }) </script>
我们通过向/site/captcha?refresh=1发送GET请求,得到的数据如下,
{"hash1":538,"hash2":538,"url":"/backend/web/site/captcha?v=56a8243edb9a8"}
很清楚的我们得到了一个新的验证码URL,
这里说下V,V是用PHP的uniqid()生成的一个唯一码
这个方法不用改YII的任何代码哦如果你在model里面进行两次验证码的验证那么你的验证就会通不过哦。
YII的验证码不论是生成的时候还是验证的时候都是通过了getVerifyCode,验证通过后会重新在生成一次验证码,所以在model里如果你调用了两次验证的话,就通不过哦
- ok 2017-03-27 已签到连续签到1天,获得了5个金钱