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

WBOY
Release: 2016-06-23 13:53:15
Original
949 people have browsed it


   $num=" ";
   for($i=0;$i      $num .=rand(0,9);
   }
   session_start();
   $_SESSION["Checknum"]=$num;
   header("Content-type:image/png");
   srand((double)microtime()*1000000);
   $im=@imagecreate(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 头

你看参考下这个:
http://blog.csdn.net/u011619326/article/details/37744855

去掉最上面的中文,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);
   $im=@imagecreate(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 头



我说了2点,你只回应了1点
自己都不对自己负责任?

我说了2点,你只回应了1点
自己都不对自己负责任?


谢谢。

我说了2点,你只回应了1点
自己都不对自己负责任?


用HTML显示文件里的图片没问题,
用php的图像处理函数 也能显示自己绘制的图片。

你那个
 
也在程序文件里吗?

你那个
 
也在程序文件里吗?


恩。我看了一篇文章http://blog.csdn.net/nicolase/article/details/7020970,好了。
多谢了。
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!