Home  >  Article  >  Backend Development  >  What should I do if the PHP verification code image does not display the image?

What should I do if the PHP verification code image does not display the image?

藏色散人
藏色散人Original
2020-10-29 10:16:172722browse

The solution to the problem that the php verification code picture does not display the picture: first check whether php has the gd extension installed; then find the php.ini file in the php directory; finally change the file encoding method to utf-8 without DOM format. And just clear the cache before the header.

What should I do if the PHP verification code image does not display the image?

Recommended: "PHP Video Tutorial"

PHP Image Verification Code Solution that cannot be displayed

Problem: Use php to implement image verification code, the page does not display

<form action="signin.php" method="post" class="col-xs-12 col-sm-4" id="post-form">
    <h2>登录</h2>
    <div class="form-group">
         <label for="username">用户名</label>
         <input type="text" class="form-control" id="username" name="username">
    </div>
    <div class="form-group">
         <label for="password">密码</label>
         <input type="password" class="form-control" id="password" name="password">
    </div>
    <div class="form-group row">
         <div class="col-xs-5">
              <label class="sr-only">验证码:</label>
              <input type="text" class="form-control" id="authcode" name="authcode" placeholder="验证码">
         </div>
         <div class="col-xs-7">
              <img  class="authcod_img" src="authcode.php"onclick="this.src=&#39;authcode.php?t=&#39;+Math.random()" name="authcode" alt="What should I do if the PHP verification code image does not display the image?" >
         </div>
     </div>
     <button type="button" class="btn btn-default">提交</button>
</form>
<?php
session_start();
 
header(&#39;Content-Type: image/png&#39;);
 
$img = imagecreatetruecolor(150, 40);
$bgcolor = imagecolorallocate($img, rand(0,100),rand(0,100),rand(0,100));
imagefill($img, 0,0,$bgcolor);

What should I do if the PHP verification code image does not display the image?

Solution:

In the windows environment, check whether the gd extension is installed in php and it is enabled

          Find the php.ini file in the php directory and look for the following statements Semicolon, remove the semicolon

Change the file encoding method to utf-8 DOM-less format

Clear the cache before the header

ob_clean();
 
header(&#39;Content-Type: image/png&#39;);

echo, print_r cannot appear before output, var_dump etc. print, comment or delete

The above is the detailed content of What should I do if the PHP verification code image does not display the image?. 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