The solution to the problem that the php verification code image cannot be displayed: first open the corresponding PHP file; then add the code as "ob_clean();" before the header output; finally save the modification.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
PHP verification code image cannot be displayed
I thought the gd2 library was not opened, but I checked with phpinfo and found that it was opened.
Solution
Add before the header output :
ob_clean(); //关键代码,防止出现'图像因其本身有错无法显示'的问题。 header("Content-type:image/jpeg");
Example:
private function outPut() { ob_clean(); //关键代码,防止出现'图像因其本身有错无法显示'的问题。 header('Content-type:image/png'); imagepng($this->img); imagedestroy($this->img); }
[Recommended learning: PHP video tutorial]
The above is the detailed content of What should I do if the php verification code image cannot be displayed?. For more information, please follow other related articles on the PHP Chinese website!