DBMNG数据库管理与应用

科学是实事求是的学问,来不得半点虚假。

thinkphp验证码设置及刷新

在控制器中:

1
2
3
4
5
6
7
8
9
    /**
     * 输出验证码
     */
    public function getverify(){
        $VModle=new \Think\Verify();
        $VModle->codeSet='0123456789';
        $VModle->length=4;
        $VModle->entry();
    }


在页面中的html

1
2
<input type="text" name="verify" placeholder="验证码" class="form-control" style="width:100px;float: left;">
 <img id="verifyimg" src="{:U('Public/getverify')}" width="100">


javacsript即时刷新

1
2
3
4
5
        $("#verifyimg").click(function() {
            var verifyURL = "{:U('Public/getverify', '', '')}";
            var time = new Date().getTime();
            $(this).attr({"src" : verifyURL+"/"+time});
        });


异步验证是否正确:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    /**
     * 异步验证验证码是否正确
     * @params verify;
     */
    public function ajaxcheckverify(){
        if(!IS_POST){
            $data['status'] = 0;
        }
        else{
            $VModle=new \Think\Verify();
            $code = trim(I('verify'));
             if(!$VModle->check($code)){
                $data['status'] = 0;
                $data['data'] = $code;
            }
            else{//验证成功
                $data['status'] = 1;
            }
        }
        echo json_encode($data);
    }
本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号