Home  >  Article  >  Backend Development  >  What should I do if the php verification code image cannot be displayed?

What should I do if the php verification code image cannot be displayed?

藏色散人
藏色散人Original
2021-03-22 09:24:402807browse

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.

What should I do if the php verification code image cannot be displayed?

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!

Statement:
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