关于验证码类的问题。。

关于验证码类的问题。。

我的验证码类是这样写的。
<?php
class image
{
        function creat_image($width,$height,$authnum)
        {
                srand((double)microtime()*1000000);
                $im = imagecreate($width,$height);
                $black = ImageColorAllocate($im, 0,0,0);
                $white = ImageColorAllocate($im, 255,255,255);
                $gray = ImageColorAllocate($im, 200,200,200);
                imagefill($im,0,0,$gray);

                //将四位整数验证码绘入图片
                imagestring($im, 5, 10, 3, $authnum, $black);
                for($i=0;$i<200;$i++)   //加入干扰象素
                {         
                    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
                    imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
                }
                ImagePNG($im);
                ImageDestroy($im);
        }
        function check_image($authinput,$authnum)
        {
                if(strcmp($authinput,$authnum)==0)
                return 1;
        }
}
?>

然后我是这样用的。。。
<?php
     Header("Content-type: image/PNG");
     require('db_fn.php');
?>
<div class="font" id="Layer10">
  
  <?php
    srand((double)microtime()*1000000);
    while(($authnum=rand()%100000)<10000);
   $image=new image();
   $authinput=$_POST['authinput'];
   if($image->check_image($authinput,$authnum)==1)
   echo "<script>alert('验证码错误!');location.href='regist.php'</script>";       
   ?>
        输入验证码:
        <input type="text" name="authinput" size="8" />
  <input type=hidden name=authnum value=<? echo $authnum; ?>>
  <?php  $image->creat_image(64,20,$authnum);?>
</div>

问题出现了,输出的时候出现下面的状况,我也不知道怎么表示。各位高手,知道是什么原因吗???

附件

{840E2F38-624F-4F00-ADB0-DF4CBCB6A824}0.jpg (46.18 KB)

2007-8-1 23:51

{840E2F38-624F-4F00-ADB0-DF4CBCB6A824}0.jpg

在你的页面上你已经定义了面面格式为:image/png
而后你又用直接用HTML语言,那样肯定出出现乱码的。

我稍微弄了一下,你好好看看吧,控制语句并没有写上:
image.php:

<?php
header("content-type:image/png");
        function creat_image($width,$height,$authnum)
        {
                srand((double)microtime()*1000000);
                $im = imagecreate($width,$height);
                $black = ImageColorAllocate($im, 0,0,0);
                $white = ImageColorAllocate($im, 255,255,255);
                $gray = ImageColorAllocate($im, 200,200,200);
                imagefill($im,0,0,$gray);

                //将四位整数验证码绘入图片
                imagestring($im, 5, 10, 3, $authnum, $black);
                for($i=0;$i<200;$i++)   //加入干扰象素
                {         
                    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
                    imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
                }
                ImagePNG($im);
                ImageDestroy($im);
        }
srand((double)microtime()*1000000);
while(($authnum=rand())<10000);
creat_image(60,20,$authnum);
?>

index.php:

<html>
<head><title>check</title></head>
<body>
<form name=check method=post>
验证码:<input type=text maxlength=5><img src=image.php>
<br>
<input type=submit>
</form>
</body>
</html>

最重要的就是这一部分:

验证码:<input type=text maxlength=5><img src=image.php>


控制语句再自己加上就OK了,呵呵!!!

搞定鸟,谢谢班竹大大。。。。