When I was doing a PHP verification code program today, I found that the generated image was not displayed. I thought it was because the PHP gd library was not opened. I checked with phpinfo and found that it can be opened. The editor below will introduce to you how to solve this problem. way.
After clearing the BOM, the code is also written starting from the top line, and the gd library is also enabled. Judging from this, it is probably not a problem with the gd library, but may be in the code of the program.
Code to generate verification code:
The code is as follows | Copy code |
/*
|
I felt like there was no problem anymore. Later, I found a senior person in Baidu who said that the key is to add ob_clean. This made me think about the reason.
Solution
ob_clean(); //Key code to prevent the problem of 'the image cannot be displayed because of its own errors'.
Add to header before output
The code is as follows
|
Copy code | ||||
truehttp: //www.bkjia.com/PHPjc/633063.htmlTechArticleWhen I was doing a php verification code program today, I found that the generated image was not displayed. I initially thought it was because the php gd library was not working. Open it. If you check it with phpinfo, it can be opened. Let me introduce it to you...