zkcncn/think-captcha

ThinkPHP验证码,兼容api模式

This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.

Maintainers

Details

gitee.com/zkcncn/think-captcha

Installs: 25

Dependents: 0

Suggesters: 0

Security: 0

pkg:composer/zkcncn/think-captcha

v1.0.1 2024-07-31 11:48 UTC

This package is not auto-updated.

Last update: 2025-09-11 11:58:57 UTC


README

thinkphp 验证码类库

安装

composer require zkcncn/think-captcha

使用

在控制器中输出验证码

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

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

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

模板里输出验证码

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

\think\facade\Route::get('captcha/[:id]', "\\think\\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)){
 //验证失败
};