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

藏色散人
Release: 2023-03-08 21:20:02
Original
2817 people have browsed it

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");
Copy after login

Example:

  private function outPut() {
        ob_clean();  //关键代码,防止出现'图像因其本身有错无法显示'的问题。
        header('Content-type:image/png');
        imagepng($this->img);
        imagedestroy($this->img);
    }
Copy after login

[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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template