• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php验证码图片不显示图片怎么办

php 搞代码 4年前 (2022-01-04) 18次浏览 已收录 0个评论

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">
    <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='a<strong style="color:transparent">来源gao@daima#com搞(%代@#码网</strong>uthcode.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);

解决方案:

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

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

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

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

在header前清除缓存

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

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

以上就是php验证码图片不显示图片怎么办的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php验证码图片不显示图片怎么办

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址