Heim  >  Artikel  >  Backend-Entwicklung  >  php注册码,该如何解决

php注册码,该如何解决

WBOY
WBOYOriginal
2016-06-13 12:04:501350Durchsuche

php注册码
一个网站的注册码显示不出来
用 firefox 看是下面的问题 (服务器返回的是 text/html, php5.4)

在本地环境 把 php 改成5.3 就能显示注册码。 服务器返回的是 image/jpeg

以下是部门调试代码,帮忙分析为什么验证码在php5.3以上版本没法正常显示?

session_register("valicode");
$width=50;    //先定义图片的长、宽 
$height= isset($_REQUEST['height'])?$_REQUEST['height']:24;
$rand_str = "";
for($i=0;$i $rand_str .= chr(mt_rand(48,57));
}
if(function_exists("imagecreate")){

echo "fuction image create exists"; //added by stone on 20140724
$_SESSION["valicode"]=strtolower($rand_str);//注册session

$img = imagecreate($width,$height);//生成图片
    imagecolorallocate($img, 255,255,255);  //图片底色,ImageColorAllocate第1次定义颜色PHP就认为是底色了 
    $black = imagecolorallocate($img,127,157,185);        

    for ($i=1; $i        imagestring($img,1,mt_rand(1,$width),mt_rand(1,$height),"#",imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255))); 
    } 

for($i=0;$i imagestring($img, mt_rand(2,5), $i*10+6, mt_rand(2,5), $rand_str[$i],imagecolorallocate($img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)));
 }

   imagerectangle($img,0,0,$width-1,$height-1,$black);//先成一黑色的矩形把图片包围

if(function_exists("imagejpeg")){
ob_clean();
header("content-type:image/jpeg\r\n"); imagejpeg($img); 
}else{ 
ob_clean();
header("content-type:image/png\r\n"); imagepng($img); 
}

imagedestroy($img);

}else{
    echo "fuction image create NOT exists"; //added by stone on 20140724
$_SESSION["valicode"]="1234";
ob_clean();
header("content-type:image/jpeg\r\n");
$fp = fopen("./valicode.jpg","r");
echo fread($fp,filesize("./validate.jpg"));
fclose($fp);
}

?>


------解决方案--------------------
echo "fuction image create exists"; //added by stone on 20140724
echo "fuction image create NOT exists"; //added by stone on 20140724
你把这两句去掉就正常了。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn