admin 管理员组文章数量: 1184232
问题:使用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='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);解决方案 :
- windows环境下,检查php是否安装gd扩展,且为开启状态
php目录下找到php.ini文件,查找如下语句
若语句前有分号,去掉分号
- 将文件编码方式改为utf-8无DOM格式
- 在header前清除缓存
ob_clean();
header('Content-Type: image/png');- 输出前不能出现echo,print_r,var_dump等打印,注释或删除
版权声明:本文标题:详解PHP图片验证码不出示的原因及快速修复方法 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1771755264a3548193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论