dataimagepng php_php用header('content-type: image/png')输出验证码,但响应回来的是text/html...

header("Content-type: image/png");

session_start();

$image = imagecreatetruecolor(70,30);

$bgcolor = imagecolorallocate($image,255,255,255);

imagefill($image,0,0,$bgcolor);

// 生成干扰像素点

for ($i=0; $i < 200; $i++) {

$pixelcolor = imagecolorallocate($image,rand(121,254),rand(121,254),rand(121,254));

imagesetpixel($image,rand(1,69),rand(1,29),$pixelcolor);

}

// 生成干扰直线

for ($i=0; $i < 4; $i++) {

$linecolor = imagecolorallocate($image,rand(121,254),rand(121,254),rand(121,254));

imageline($image,rand(0,69),rand(0,29),rand(0,69),rand(0,29),$linecolor);

}

$captch_code = "";

// 生成验证码

for ($i=0; $i < 4; $i++) {

$fontsize = 6;

$fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));

$data = 'abcdefghijkmnpqrstuvwxy3456789';

$fontcontent = substr($data,rand(0,strlen($data)-1),1);

$captch_code .= $fontcontent;

$x = ($i*70/4)+rand(5,10);

$y = rand(5,10);

imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);

}

$_SESSION['authcode'] = $captch_code;

imagepng($image);

imagedestroy($image);

上面为生成验证码的代码,在本地服务器可以生成验证码,但把代码上传到远程服务器后就无法生成验证码,返回500(intetnal server error)错误,远程服务器已开启GD库,代码开头header('content-type: image/png'),但响应回来的却是text/html。

远程服务器返回text/html

本地成功返回image/png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值