温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php验证码图片不显示图片的解决方法

发布时间:2020-10-30 09:52:08 来源:亿速云 阅读:738 作者:小新 栏目:编程语言

这篇文章主要介绍php验证码图片不显示图片的解决方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

php验证码图片不显示图片的解决办法:首先检查php是否安装gd扩展;然后在php目录下找到php.ini文件;最后将文件编码方式改为utf-8无DOM格式,并在header前清除缓存即可。

PHP图片验证码无法显示的解决方案

问题:使用php实现图片验证码,页面不显示

<form action="signin.php" method="post" class="col-xs-12 col-sm-4" id="post-form">
    <h3>登录</h3>
    <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">
         </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);

php验证码图片不显示图片的解决方法

解决方案:

windows环境下,检查php是否安装gd扩展,且为开启状态

php目录下找到php.ini文件,查找如下语句

若语句前有分号,去掉分号

将文件编码方式改为utf-8无DOM格式

在header前清除缓存

ob_clean();
 
header('Content-Type: image/png');

输出前不能出现echo,print_r,var_dump等打印,注释或删除

以上是php验证码图片不显示图片的解决方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI