標籤:des style blog io color ar sp for div
1 <?php 2 //驗證碼製作 3 4 session_start(); 5 //產生驗證碼圖片 6 Header("Content-type: image/PNG"); 7 $im = imagecreate(44,18); // 畫一張指定寬高的圖片 8 $back = ImageColorAllocate($im, 245,245,245); // 定義背景顏色 9 imagefill($im,0,0,$back); //把背景顏色填充到剛剛畫出來的圖片中10 $vcodes = "";11 srand((double)microtime()*1000000);12 $srcstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 13 //產生4位元字14 for($i=0;$i<4;$i++) {15 $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 產生隨機顏色16 $authnum = $srcstr[mt_rand(0,35)];17 $vcodes.= $authnum;18 imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);19 }20 $_SESSION[‘VCODE‘] = $vcodes;21 22 for($i=0;$i<100;$i++) {//加入幹擾象素 23 $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));24 imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 畫像素點函數25 }26 ImagePNG($im);27 ImageDestroy($im); 28 ?>
PHP 產生驗證碼 (二)