PHP 验证图片显示红XX

<?php
$img=imagecreate(100,30);
$bg=imagecolorallocate($img,0,0,0);//背景
$te=imagecolorallocate($img,255,255,255);//字体颜色
imagestring($img,3,0,0,"egeryh",$te);
header("content-type:image/jpeg");
imagejpeg($img);

?>
浏览可以正常显示

修改成下面 的
<?php
$year="1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
$arr=explode(",",$arr);
for($i=0;$i<4;$i++){
$imgNum.=$arr[rand(0,35)];
}
$img=imagecreate(100,30);
$bg=imagecolorallocate($img,0,0,0);//背景
$te=imagecolorallocate($img,255,255,255);//字体颜色
imagestring($img,3,0,0,"egeryh",$te);
header("content-type:image/jpeg");
imagejpeg($img);
?>
还没把$imgnum加到图片上呢,却显示不出来图片

求帮助

session_start();
//计算方法
$calArray=array("+","-");
$randa = rand(1,50);
$randb = rand(1,50);
$calRand=rand(0,1);
$clacmethod=$calArray[$calRand];//随机加减法

$pic= $randa.$clacmethod.$randb."="; //生成的图片表达式
$result=($clacmethod=="+")?$randa+$randb:$randa-$randb;

$len=strlen($pic); //字符长度
header("Content-type: image/gif");
$_SESSION['chkCode'] = $result;
$im = @imagecreate(90, 25);
$bg=imagecolorallocate($im, 240, 240, 240);
$loc = 2;
$color1=imagecolorallocate($im, 0, 0, 0);

for($i=0;$i<$len;$i++){
$color=imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
imagestring($im, 5, ($loc+2), 5, substr($pic,$i,1), $color1);
imagestring($im, 5, $loc, 5, substr($pic,$i,1), $color);
$loc += 13;
}
Imagegif($im);
imagedestroy($im);
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜