Home > Article > Backend Development > What should I do if the verification code image generated by php cannot be opened?
Solutions to the problem that the image generated by php cannot be opened: 1. Block the code for the output image; 2. Check for code errors; 3. Check whether the gd library is open; 4. Modify the font when generating the verification code Path; 5. Add the "ob_clean()" code.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
What should I do if the image generated by php cannot be opened?
The verification code image generated by php does not display the problem
1. First block the code of the output image: header("Content-Type:image/png");
2. Access the image and check for code errors
3. Then check whether there is output before the verification code. If there is output, the verification code will not be displayed
4.Check gd Is the library open?
5. The verification code is not displayed and no error is reported; refresh the page and the verification code disappears in a flash. The reason is: the font path is incorrect when generating the verification code (must be an absolute path), as shown in the figure :
#6. If there are no problems, add the ob_clean() code before header("Content-Type:image/png") to solve the problem perfectly. (Note: The function of ob_clean() is to clear the ob cache)
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if the verification code image generated by php cannot be opened?. For more information, please follow other related articles on the PHP Chinese website!