ok

ok

这家伙有点懒,还没写个性签名!

  • 财富值50
  • 威望值0
  • 总积分190

个人信息

  • 现在是,打开页面验证码就现实不了。

  • 提出了问题
    Yii2.x 中captcha 验证码再actions的配置问题
  • 回复了 的回复

    为啥我生成验证码图片失败呢?

    为什么我的是 路径不写就生成了。

  • 赞了回复

    前台验证成功,表单提交就提示验证码错误;原因可能是ajax验证一次 致使验证码在session中已经变了 再提交就提示错误了 怎么解决?

  • 回复了 的评论

    我也发个吧
    在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的大小就不生效了。

  • 赞了评论

    我也发个吧
    在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里如果你调用了两次验证的话,就通不过哦

  • 2017-03-27 已签到
    连续签到1天,获得了5个金钱
助理 等级规则
190/200
资料完整度
30/100
用户活跃度
0/100

Ta的关注

4

Ta的粉丝

1

Ta的访客

7