国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home 類庫(kù)下載 PHP類庫(kù) thinkphp verification code

thinkphp verification code

Oct 09, 2016 pm 01:33 PM

thinkphp自帶驗(yàn)證碼

前端頁(yè)面:

<div style="position:absolute;z-index:3;top:160px;left:180px;">
    <img  src="/static/imghw/default1.png"  data-src="{:U(&#39;Verify&#39;)}"  class="lazy"    style="max-width:90%"  onclick="this.src=this.src+&#39;?&#39;+Math.random()" id="safecode" style="height:50px;width:70%;"/ alt="thinkphp verification code" ></div>
//驗(yàn)證碼判斷
 public function Verify(){
 ob_clean();
        //顯示驗(yàn)證碼
        $cfg=array(
            &#39;codeSet&#39;   =>  &#39;0123456789&#39;,    // 驗(yàn)證碼字符集合
            &#39;imageH&#39;    => 25,               // 驗(yàn)證碼圖片高度
            &#39;imageW&#39;    =>  80,               // 驗(yàn)證碼圖片寬度
            &#39;length&#39;    =>  4,               // 驗(yàn)證碼位數(shù)
            &#39;fontttf&#39;   =>  &#39;4.ttf&#39;,              // 驗(yàn)證碼字體,不設(shè)置隨機(jī)獲取
            &#39;fontSize&#39;  =>  10,              // 驗(yàn)證碼字體大小(px)
            &#39;useNoise&#39;  =>  false,            // 是否添加雜點(diǎn)
            &#39;useCurve&#39;  =>  false,            // 是否畫混淆曲線
            &#39;bg&#39;        =>  array(226,229,236) //背景顏色
            );
        $very=new \Think\Verify($cfg);
        $very->entry();
    } 
//客戶端通過(guò)ajax,實(shí)現(xiàn)校驗(yàn)驗(yàn)證碼
    public function checkVerify(){
        $code = I(&#39;get.code&#39;);
        $very = new \Think\Verify();
        $key = $this->auth_my_code($very,$very->seKey);
        // 驗(yàn)證碼不能為空
        $secode = session($key);

        //對(duì)$code進(jìn)行加密,在比較校驗(yàn)
        if($this->auth_my_code($very,strtoupper($code)) == $secode[&#39;verify_code&#39;]) {
            echo json_encode(array(&#39;flag&#39;=>1,&#39;cont&#39;=>&#39;驗(yàn)證碼正確&#39;));
        }else{
            echo json_encode(array(&#39;flag&#39;=>2,&#39;cont&#39;=>&#39;驗(yàn)證碼錯(cuò)誤&#39;));
        }
    }
    private function auth_my_code($vry,$str){
        $key = substr(md5($vry->seKey), 5, 8);
        $str = substr(md5($str), 8, 10);
        return md5($key . $str);
    }

以上驗(yàn)證碼如果輸入錯(cuò)誤提交后不能自動(dòng)刷新,對(duì)代碼進(jìn)行更改后:

location.href="/Login/Login";這樣只能對(duì)整個(gè)頁(yè)面刷新,提交表單的值可能會(huì)丟失,非常影響用戶體驗(yàn)。

2.如果驗(yàn)證碼輸入錯(cuò)誤,提交后自動(dòng)刷新驗(yàn)證碼。

else{
       $(&#39;#safecode&#39;).attr("src","/Login/Verify?"+Math.random());
         NewAlert(2,"驗(yàn)證碼有誤,請(qǐng)重新輸入",null);
         code_ok = false;
         $(&#39;#verifyresult&#39;).html(msg.cont).css({&#39;color&#39;:&#39;red&#39;,&#39;font-size&#39;:&#39;12px&#39;});  
        }

3.以下為ajax提交驗(yàn)證碼到后臺(tái)校驗(yàn):

<script type="text/javascript">

$("#login_btn").click(function(){
       var username = $.trim($("#username").val());
       var password = $.trim($("#password").val());
       var code = $(&#39;#veri&#39;).val();
        if(username == ""){
            NewAlert(2,"請(qǐng)輸入用戶名",null);
            shutdown();
            return false;
        }else if(password == ""){
            NewAlert(2,"請(qǐng)輸入密碼",null);
            shutdown();
            return false;
        }else if(code==&#39;&#39;){
            NewAlert(2,"請(qǐng)輸入驗(yàn)證碼",null);
            return false;
        }

        //ajax去服務(wù)器端校驗(yàn)
        $.ajax({
            url:"__CONTROLLER__/checkVerify",
            data:{&#39;code&#39;:code},
            dataType:&#39;json&#39;,
            success:function(msg){
                if(msg.flag==1){
                  var data= {
                       username:username,
                       password:password
                     };
                     $.ajax({
                             type:"POST",
                             url:"{:U(&#39;Login/Login&#39;)}",
                             data:data,
                             dataType:"json",
                             success:function(msg){
                                 if(msg.RespCode==&#39;000&#39;){
                                     shutdown();
                                     if(msg.org_code==&#39;fcb&#39;){
                                         location.href="/Invest/index?biao_type=cwb";
                                     }else{
                                         location.href="{$Think.config.VIP_URL}/Individual/index";
                                     }
                                 }else{
                                     NewAlert(2,msg.RespDesc,null);
                                     return false;
                                 }
                             },
                             error:function(){
                                 shutdown();
                             },
                             beforeSend: function() {
                                 Loading();
                             },
                         });
                   }else{
                           $(&#39;#safecode&#39;).attr("src","/Login/Verify?"+Math.random());
                        NewAlert(2,"驗(yàn)證碼有誤,請(qǐng)重新輸入",null);
                        code_ok = false;
                        $(&#39;#verifyresult&#39;).html(msg.cont).css({&#39;color&#39;:&#39;red&#39;,&#39;font-size&#39;:&#39;12px&#39;});  
                }
            }
        });
});    

</script>


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276