Home> PHP Framework> ThinkPHP> body text

Simplify think-captcha verification code under ThinkPHP6 and improve text recognition

幸运切糕
Release: 2020-05-02 10:09:49
Original
3327 people have browsed it

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 latestthinkphp6.0think-captchaextension 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!

think-captcha verification code

Controller test code:


        
Copy after login

View test code :

    Title 
Copy after login

The verification code rendered by default is as follows:

Simplify think-captcha verification code under ThinkPHP6 and improve text recognition

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.

Optimize think-captcha verification code

Find theconfig\captcha.phpconfiguration file and modify the following parts:

//验证码位数 'length' => 4, //简洁的4字符验证码 // 验证码字符集合 'codeSet' => '0123456789', //这里我去掉英文了,只留下数字部分 // 是否使用混淆曲线 'useCurve' => false, //是否添加杂点 'useNoise' => false, // 验证码字体 不设置则随机 'fontttf' => '4.ttf', //经测试,该字体很顺眼
Copy after login

Refresh after modification to see if it is more concise?

Simplify think-captcha verification code under ThinkPHP6 and improve text recognition

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);
Copy after login

Finally take a look at the effect, are you satisfied?

Simplify think-captcha verification code under ThinkPHP6 and improve text recognition

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!