Skip to content

tobycroft/think-captcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

think-captcha

thinkphp8+ PHP8.5+ captcha验证码类库

区别

  • 支持 PHP8.5+
  • 支持 thinkphp8+

安装

composer require tobycroft/think-captcha

使用

详细 Demo

  • 你可以在 AOSSTP8这个项目中的 captcha 目录下查看详细的 Demo,涵盖了验证码的所有功能以及额外的骚操作

在控制器中输出验证码

在控制器的操作方法中使用

public function captcha($id = '')
{
    return captcha($id);
}

然后注册对应的路由来输出验证码

模板里输出验证码

首先要在你应用的路由定义文件中,注册一个验证码路由规则。

\think\facade\Route::get('captcha/[:id]', "\\tobycroft\\captcha\\CaptchaController@index");

然后就可以在模板文件中使用

<div>{:captcha_img()}</div>

或者

<div><img src="{:captcha_src()}" alt="captcha" /></div>

上面两种的最终效果是一样的

控制器里验证

使用 TP 的内置验证功能即可

$this->validate($data,[
    'captcha|验证码'=>'require|captcha'
]);

或者手动验证

if(!captcha_check($captcha)){
 //验证失败
};

About

thinkphp8.x 验证码类库 2026 版

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages