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);
// 生成干擾像素點(diǎn)
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 = "";
// 生成驗(yàn)證碼
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);
上面為生成驗(yàn)證碼的代碼,在本地服務(wù)器可以生成驗(yàn)證碼,但把代碼上傳到遠(yuǎn)程服務(wù)器后就無法生成驗(yàn)證碼,返回500(intetnal server error)錯(cuò)誤,遠(yuǎn)程服務(wù)器已開啟GD庫,代碼開頭header('content-type: image/png'),但響應(yīng)回來的卻是text/html。
遠(yuǎn)程服務(wù)器返回text/html
本地成功返回image/png
總結(jié)
以上是生活随笔為你收集整理的dataimagepng php_php用header('content-type: image/png')输出验证码,但响应回来的是text/html...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何听节拍器_我是如何开垮一家琴行的!
- 下一篇: c++ fstream用得多不?_护肤品