The following thinkphp framework tutorial column will introduce to you the solution to the problem that the ThinkPHP verification code is not displayed. I hope it will be helpful to friends in need!
I encountered a very strange BUG today, that is, I wrote a PHP program that runs normally locally, but when it is published to Party A's server, there is a BUG that the verification code cannot be displayed. .
The specific manifestation is that a small cracked picture icon is displayed on the Chrome browser. Right-click the picture to open it in a new window. It is still a small cracked picture, not Error message (when xdebug extension and php error reporting are enabled), if so, it means that there is no problem with the verification code URL routing and business logic code, but there is a problem with the verification code generation process. My debugging idea is as follows:
1. Check whether the GD library is installed correctly. Linux recommends using yum, apt, or pecl to install it. Windows recommends using the phpStudy integrated environment. It has integrated commonly used extensions and can be opened with the right mouse button. (Applicable to situations where the verification code image displays an error message and a bunch of garbled characters when it opens in a new window. If there is an error message, please debug according to the error message)
2. Check whether the font called by the verification code is missing. Some fonts called by the verification code components are not installed on the target computer. This requires analysis of the source code of the verification code module. I use ThinkPHP’s official think-captcha. You can find its source code at vendortopthinkthink-captchasrc. You can see here at vendortopthinkthink-captchaassets that this verification code plug-in comes with its own font, so ThinkPHP’s verification code is basically unnecessary. Considering the font issue, if it is another verification code plug-in, you still need to check this place.
3. Download the buggy verification code image and the local test normal verification code image, use Notepad to view and compare.
#The picture above is the notepad of the verification code image in the local environment. We use a more professional hexadecimal editor to analyze the file differences.
As shown in the picture, we found that the bad file bad has exactly the same content except for the addition of EF BB BF and other numbers in front of it, indicating that PHP has too many errors when rendering the image. These texts were rendered. As for the reason, I guess it may be that there is no professional code editor on the server, so the operation and maintenance personnel used ordinary Windows Notepad to modify the PHP code, resulting in the addition of this BOM header.
If it is the third reason, there are two solutions. One is to use ob_clean to clear the output buffer of php before calling the imagepng output image code of the verification code. There is also the use of some tools to remove the BOM of the code in batches.
I use ob_clean here, add ob_clean() before line 203 of Captcha.php, the main file of think-captcha, so that it can be solved once and for all. If you have strict requirements on performance and stability, it is recommended to use tools to remove BOM in batches, which is safer. At the same time, it is also recommended that you install a professional code editor such as editplus on the server at any time. Do not use Windows Notepad to modify the code.
The above is the detailed content of Solve the problem of ThinkPHP verification code not displaying. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use