验证码自定义

1、首先确认文件夹\vendor\topthink\think-captcha存在

 

//显示验证码
public function show_captcha(){
$captcha = new \think\captcha\Captcha();
$captcha->imageW=121;
$captcha->imageH = 32; //图片高
$captcha->fontSize =14; //字体大小
$captcha->length = 4; //字符数
$captcha->fontttf = '5.ttf'; //字体
$captcha->expire = 30; //有效期
$captcha->useNoise = false; //不添加杂点
return $captcha->entry();
}

 

 

<img class="code_img" src="/admin/login/show_captcha" onclick="this.src='{:captcha_src()}?'+Math.random();" alt="captcha" />

 

 

 

  1. //提交
    public function login_post(){
    $code=input('post.captcha');
    $captcha = new \think\captcha\Captcha();
    $result=$captcha->check($code);
    if($result===false){
    echo '验证码错误';exit;
    }
    echo '验证码正确,继续';exit;
    }

posted @ 2019-01-22 11:05  我是谁,我在做什么  阅读(258)  评论(0编辑  收藏  举报