<?php 
/* 
 *   Filename: authimg.php 
 *   Author:   hutuworm 
 *   Date:     2003-04-28 
 *   @Copyleft hutuworm.org 
 */ 
//生成验证码图片 
//setcookie("authnum",md5($pass),0);
error_reporting(2039);
$authnum= make_pass(5,8);
setcookie("authnum",$authnum,0);
setcookie("authnum_org",md5($authnum),0);
Header("Content-type: image/PNG");  
header("Content-Disposition: inline; filename=$authnum");
srand((double)microtime()*1000000); 
$img_height=100;
$img_width=20;
$aimg = imageCreate($img_height,$img_width);    
ImageColorAllocate($aimg, 255,255,255);  
$black = ImageColorAllocate($aimg, 0,0,0);  
ImageRectangle($aimg,0,0,$img_height-1,$img_width-1,$black);
for ($i=1; $i<=100; $i++) {  
  imageString($aimg,1,mt_rand(1,$img_height),mt_rand(1,$img_width),"*",imageColorAllocate($aimg,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255))); 
} 

 imagestring($aimg, 5, 10, 3, $authnum, $black); 
 Header("Content-type: image/png");    //告诉浏览器，下面的数据是图片，而不要按文字显示 
 ImagePng($aimg);                    //生成png格式。。。嘿嘿效果蛮像回事的嘛。。。 
 ImageDestroy($aimg);
function make_pass($min, $max){
$pass="";
$length = mt_rand($min, $max);
$deck = array_merge (
        range("0", "9"),
        range("a", "z"),
        range("A", "Z"),
        array("0", "1", "2", "3", "4", "5", "6", "8", "9"));
for($i = 0; $i < $length; $i++){
        $shuffle = mt_rand(0, sizeof($deck)-1);
        $pass .= $deck[$shuffle];
}
return $pass;
}
?>