thinkphp6 验证码总是提示不正确 | 您所在的位置:网站首页 › 一直提示验证码错误 › thinkphp6 验证码总是提示不正确 |
1.首先安装验证码扩展包 composer require topthink/think-captcha2.引用 use think\captcha\facade\Captcha;3.调用 public function verify() { return Captcha::create(); }4.验证 if(!Captcha::check($verity)) { $result['status']=0; $result['msg']="验证码不正确!"; return json_encode($result); exit; }这一步总是提示不正确,后来看文档说Thinkphp6默认是不开启的,需要开启Session才能有效。 在应用app目录下找到文件middleware.php文件,把里面注释的代码\think\middleware\SessionInit::class开启就行了 // 全局中间件定义文件 return [ // 全局请求缓存 // \think\middleware\CheckRequestCache::class, // 多语言加载 // \think\middleware\LoadLangPack::class, // Session初始化 \think\middleware\SessionInit::class ];
|
CopyRight 2018-2019 实验室设备网 版权所有 |