1、首先确认文件夹vendor opthink hink-captcha存在
//显示验证码
public function show_captcha(){
$captcha = new hinkcaptchaCaptcha();
$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" />
-
//提交
public function login_post(){
$code=input('post.captcha');
$captcha = new hinkcaptchaCaptcha();
$result=$captcha->check($code);
if($result===false){
echo '验证码错误';exit;
}
echo '验证码正确,继续';exit;
}