生成验证码图片,并输出;如何输出的总是X的图片

WBOY
Release: 2016-06-13 12:02:58
Original
901 people have browsed it

生成验证码图片,并输出;怎么输出的总是X的图片

   $num=" ";
   for($i=0;$i     $num .=rand(0,9);
   }
   session_start();
   $_SESSION["Checknum"]=$num;
   header("Content-type:image/png");
   srand((double)microtime()*1000000);
   [email protected](60,20);
   @imagecolorallocate($im,255,255,255);
   $black=imagecolorallocate($im,0,0,0);
   $gray=imagecolorallocate($im,200,200,200);
   imagefill($im,0,0,$gray);
   $style=array($black,$black,$black,$black,$black,$gray,$gray,$gray,$gray,$gray);
   imagesetstyle($im,$style);
   $y1=rand(0,20);
   $y2=rand(0,20);
   $y3=rand(0,20);
   $y4=rand(0,20);
   imageline($im,0,$y1,60,$y3,IMG_COLOR_STYLED);
   imageline($im,0,$y2,60,$y4,IMG_COLOR_STYLED);
   for($i=0;$i     imagesetpixel($im,rand(0,60),rand(0,20),$black);
   }
   $strx=rand(3,8);
   for($i=0;$i     $strpos=rand(1,6);
 imagestring($im,5,$strx,$strpos,substr($num,$i,1),$black);
 $strx+=rand(8,12);
   } 
   imagepng($im);
   imagedestroy($im); 
?>
------解决方案--------------------
1、没有加载 GD 扩展
2、程序文件有 BOM 头
------解决方案--------------------
去掉最上面的中文,session_start() 修改一下位置,似乎就可以了

session_start();
   $num=" ";
   for($i=0;$i     $num .=rand(0,9);
   }
   
   $_SESSION["Checknum"]=$num;
   header("Content-type:image/png");
   srand((double)microtime()*1000000);
   [email protected](60,20);
   @imagecolorallocate($im,255,255,255);
   $black=imagecolorallocate($im,0,0,0);
   $gray=imagecolorallocate($im,200,200,200);
   imagefill($im,0,0,$gray);
   $style=array($black,$black,$black,$black,$black,$gray,$gray,$gray,$gray,$gray);
   imagesetstyle($im,$style);
   $y1=rand(0,20);
   $y2=rand(0,20);
   $y3=rand(0,20);
   $y4=rand(0,20);
   imageline($im,0,$y1,60,$y3,IMG_COLOR_STYLED);
   imageline($im,0,$y2,60,$y4,IMG_COLOR_STYLED);
   for($i=0;$i     imagesetpixel($im,rand(0,60),rand(0,20),$black);
   }
   $strx=rand(3,8);
   for($i=0;$i     $strpos=rand(1,6);
 imagestring($im,5,$strx,$strpos,substr($num,$i,1),$black);
 $strx+=rand(8,12);
   } 
   imagepng($im);
   imagedestroy($im); 
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!