zhh2100 / pidan-captcha
pidan 验证码包 同步到 v3.0.8 于 2022 年 10 月 26 日
v1.0.9
2023-04-09 10:24 UTC
Requires
- zhh2100/framework: ^1.1.1
README
pidanphp6 验证码类库
安装
composer require pidan/pidan-captcha
使用
在控制器中输出验证码
在控制器的操作方法中使用
public function captcha($id = '')
{
return captcha($id);
}
然后注册对应的路由来输出验证码
模板中输出验证码
首先需要在你的应用路由定义文件中,注册一个验证码路由规则。
\pidan\facade\Route::get('captcha/[:id]', "\\pidan\\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)){
//验证失败
};