很久以前写的 php生成图片验证码 今天整理了一下 存到blog上 <?php session_start(); function randstr_create($len = 4){ $str = '';$all = array_merge(range(0,9),range('A','Z')); foreach(array_rand($all,$len) as $value){$str .= $all[$value];} return $str; } $code = $_SESSION['authcode'] = randstr_create(); $im = imagecreate(60,20); $gray = ImageColorAllocate($im, 125,109,124); $pink = ImageColorAllocate($im,238,227,232); ImageFill($im,0,0,$pink); for($i=0;$i<100;$i++) { $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imagesetpixel($im, rand()%60 , rand()%40 , $randcolor); } for($i=0;$i<6;$i++) { $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imageline($im,rand()%60,rand()%40,rand()%40,rand()%60,$randcolor); } ImageTTFText($im,13,3,6,16,$gray,"C:/windows/fonts/ARIAL.TTF",$code); Header("Content-type: image/gif"); ImageGif($im); ImageDestroy($im); ?>