


Reasons and solutions for TP6 verification code verification failure
Jan 26, 2020 pm 10:16 PMFirst use Composer to install the think-captcha extension package:
composer require topthink/think-captcha
The controller introduces use think\captcha\facade\Captcha;
public function verify()
{
return Captcha::create();
}
Verify verification code
if( !Captcha::check($vercode)) { return json(['code'=>1001, 'msg'=>'验证码错误'); }
Check method
/** * 验证验证码是否正确 * @access public * @param string $code 用户验证码 * @return bool 用户验证码是否正确 */ public function check(string $code): bool { if (!$this->session->has('captcha')) { return false; } $key = $this->session->get('captcha.key'); $code = mb_strtolower($code, 'UTF-8'); $res = password_verify($code, $key); if ($res) { $this->session->delete('captcha'); } return $res; }
From the above check method, we can see that verification code verification requires session, and Thinkphp6 defaults to If it is not enabled, you need to initialize it according to the manual.
Find the global middleware middleware.php file in the application app directory, and enable the code \think\middleware\SessionInit::class commented below.
// 全局中间件定义文件 return [ // 全局请求缓存 // \think\middleware\CheckRequestCache::class, // 多语言加载 // \think\middleware\LoadLangPack::class, // Session初始化 \think\middleware\SessionInit::class ]
The above is the detailed content of Reasons and solutions for TP6 verification code verification failure. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are several versions of thinkphp

Which one is better, laravel or thinkphp?

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks

ThinkPHP6 data encryption and decryption: protecting sensitive data security
