写的太早了,你自己调试下。
<?php
/*
*       Filename:   authimg.php
*       Author:       唯她
*       Date:           2003年6月3日
*       @Copyleft   www.vitalstudio.cn
*/
session_start();
srand((double)microtime()*1000000);
while(($authnum=rand()%10000) &lt; 1000);//生成四位随机整数验证码
$_SESSION['auth']=$authnum;
//生成验证码图片
Header("Content-type:   image/png");
$im   =   imagecreate(45,16);
$black   =   ImageColorAllocate($im,   200,10,0);
$white   =   ImageColorAllocate($im,   255,255,255);
$gray   =   ImageColorAllocate($im,   230,230,230);   //将这两行提前至   $im   ..下面
imagefill($im,68,30,$gray);
//将四位整数验证码绘入图片
//位置交错
for   ($i   =   0;   $i   &lt;   strlen($authnum);   $i++)   {
if   ($i%2   ==   0)   $top   =   0;
else   $top   =   2;
imagestring($im,   5,   10*$i+3,   $top,   substr($authnum,$i,1),   $black);
}
for($i=0;$i&lt;250;$i++)       //加入干扰象素
{
imagesetpixel($im,   rand()%70   ,   rand()%30   ,   $black);
}
ImagePNG($im);
ImageDestroy($im);
?>