Home >Backend Development >PHP Problem >What should I do if the PHP verification code image does not display the image?
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.
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='authcode.php?t='+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('Content-Type: image/png'); $img = imagecreatetruecolor(150, 40); $bgcolor = imagecolorallocate($img, rand(0,100),rand(0,100),rand(0,100)); imagefill($img, 0,0,$bgcolor);
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('Content-Type: image/png');
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!