English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
프론트엔드 페이지:
<div style="position:absolute;z-index:3;top:160px;left:180px;"> <img style="cursor:pointer; " src="{:U('Verify')}" onclick="this.src=this.src+'?'+Math.random()" id="safecode" style="height:50px;width:70%;"/> </div> //인증 코드 판단 public function Verify(){ ob_clean(); //인증 코드 표시 $cfg=array( 'codeSet' => '0123456789', // 인증 코드 문자 집합 'imageH' => 25, // 인증 코드 이미지 높이 'imageW' => 80, // 인증 코드 이미지 너비 'length' => 4, // 'fontttf' => '4.ttf', // 인증 코드 글자, 설정하지 않으면 무작위로 가져옵니다 'fontSize' => 10, // 인증 코드 글자 크기(px) 'useNoise' => false, // 섬유를 추가할지 여부 'useCurve' => false, // 혼란선을 그릴지 여부 'bg' => array(226,229,236) //배경 색상 ); $very=new \Think\Verify($cfg); $very->entry(); } //客户端를 통해 AJAX를 사용하여 인증 코드를 검증합니다 public function checkVerify(){ $code = I('get.code'); $very = new \Think\Verify(); $key = $this->auth_my_code($very,$very->seKey); // 인증 코드가 비어 있을 수 없습니다 $secode = session($key); //对$code进行加密,在比较校验 if($this->auth_my_code($very,strtoupper($code)) == $secode['verify_code']) { echo json_encode(array('flag'=>1,'cont'=>'验证码正确')); } echo json_encode(array('flag'=>2,'cont'=>'验证码错误'); } } private function auth_my_code($vry,$str){ $key = substr(md5($vry->seKey), 5, 8); $str = substr(md5($str), 8, 10); return md5($key . $str); }
以上验证码如果输入错误提交后不能自动刷新,对代码进行更改后:
location.href="/Login/Login";这样只能对整个页面刷新,提交表单的值可能会丢失,非常影响用户体验。
2.如果验证码输入错误,提交后自动刷新验证码。
else{ $('#safecode').attr("src","/Login/Verify?"+Math.random()); NewAlert(2,"인증 코드가 잘못되었습니다. 다시 입력하십시오",null); code_ok = false; $('#verifyresult').html(msg.cont).css({'color':'red','font-size':'12px'}); }
3.以下为ajax提交验证码到后台校验:
<script type="text/javascript"> $("#login_btn").click(function(){ var username = $.trim($("#username").val()); var password = $.trim($("#password").val()); var code = $('#veri').val(); if(username == ""){ NewAlert(2,"请输入用户名",null); shutdown(); return false; }else if(password == ""){ NewAlert(2,"请输入密码",null); shutdown(); return false; }else if(code==''){ NewAlert(2,"请输入验证码",null); return false; } //ajax去服务器端校验 $.ajax({ url:"__CONTROLLER__",/checkVerify", data:{'code':code}, dataType:'json', success:function(msg){ if(msg.flag==1}{ var data= { username:username,, password:password }); $.ajax({ type:"POST", url:"{:U('Login",/Login')", data:data:, dataType:"json", success:function(msg){ if(msg.RespCode=='000'){ shutdown(); if(msg.org_code=='fcb'){ location.href="/Invest/index?biao_type=cwb"; } location.href="{$Think.config.VIP_URL}/Individual/index"; } } NewAlert(2,msg.RespDesc,null); return false; } , error:function(){ shutdown(); , beforeSend: function() { Loading(); , }); } $('#safecode').attr("src","/Login/Verify?"+Math.random()); NewAlert(2,"인증 코드가 잘못되었습니다. 다시 입력하십시오",null); code_ok = false; $('#verifyresult').html(msg.cont).css({'color':'red','font-size':'12px'}); } } }); }); </
3codebox.com(이메일을 보내면, #을 @으로 변경하십시오. 기타 증거를 제공하여 신고하시면, 사이트는 즉시 저작권 침해 내용을 제거합니다.),