Home >PHP Framework >ThinkPHP >Simplify think-captcha verification code under ThinkPHP6 and improve text recognition
As we all know, the verification code can prevent malicious login registration. It is generated by the server, sent to the client, and finally displayed in image format. Complex verification codes can improve the security of the website, but overly complex verification codes will also make it extremely difficult to recognize text with the naked eye, greatly reducing the user experience.
This article uses the latest thinkphp6.0
think-captcha
extension as the modification object to explain in detail how to simplify the display of verification codes, improve text recognition, and make the elderly People can see clearly too!
Controller test code:
<?php namespace app\controller; use app\BaseController; use think\facade\View; class Index extends BaseController { public function index() { return View::fetch(); } }
View test code :
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <img src="{:captcha_src()}" alt=""> </body> </html>
The verification code rendered by default is as follows:
Some friends may think this is very clear, but for older people It is still difficult for older people. In addition, by modifying the verification code file, you can also improve your hands-on ability and increase your knowledge.
Find the config\captcha.php
configuration file and modify the following parts:
//验证码位数 'length' => 4, //简洁的4字符验证码 // 验证码字符集合 'codeSet' => '0123456789', //这里我去掉英文了,只留下数字部分 // 是否使用混淆曲线 'useCurve' => false, //是否添加杂点 'useNoise' => false, // 验证码字体 不设置则随机 'fontttf' => '4.ttf', //经测试,该字体很顺眼
Refresh after modification to see if it is more concise?
This is actually quite good. Under normal circumstances, it is not recommended to modify the framework, but for the purpose of learning, we will further optimize it.
Openvendor\topthink\think-captcha\src\Captcha.php
Modify line 277 and remove the font tilt
imagettftext($this->im, $this->fontSize, 0, $x, $y, $this->color, $fontttf, $char);
Finally take a look at the effect, are you satisfied?
This article simplifies the display of the verification code and improves the performance by simply modifying the configuration file and removing the inclination. Regarding text recognition, friends, the more you practice, the more profound your impression will be!
The above is the detailed content of Simplify think-captcha verification code under ThinkPHP6 and improve text recognition. For more information, please follow other related articles on the PHP Chinese website!