thinkPHP快速创建验证码

来源:互联网 发布:python保存文件 编辑:程序博客网 时间:2024/05/21 23:26

1.在方法中/commom/function

/*验证码检测*/function check_code($code){    $verify = new \Think\Verify();    return $verify->check($code);}

2.在控制器中

public function selfverify(){        $config =    array(            'length'      =>    4,     // 验证码位数           );        ob_clean();       $Verify = new \Think\Verify($config);        $Verify->entry();}

if(isset($_POST['code'])){            $code = $_POST['code'];            if(check_code($code) === false){                $this->error('验证码错误','/Admin/Login',1);            }}

3.在模版中

<img style="height:36px" src="{:U('/Admin/Login/selfverify','','')}"  onclick="this.src='{:U('/Admin/Login/selfverify','','')}?d='+Math.random();" />


1 0
原创粉丝点击