国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php標準生成驗證碼程序

2024-05-04 23:06:25
字體:
來源:轉載
供稿:網友
  1. <?php 
  2. session_start(); 
  3. $enablegd = 1; 
  4. //判斷圖像處理函數是否存在 
  5. $funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imagestring','imageline','imagerotate','imagedestroy','imagecolorallocatealpha','imageellips教程e','imagepng'); 
  6. foreach($funcs as $func) 
  7.  if(!function_exists($func)) 
  8.  { 
  9.   $enablegd = 0; 
  10.   break
  11.  } 
  12.  
  13. ob_clean(); //清理緩沖 
  14.  
  15. if($enablegd) 
  16.  //create captcha 
  17.  $consts = 'cdfgkmnpqrstwxyz23456'
  18.  $vowels = 'aek23456789'
  19.  for ($x = 0; $x < 6; $x++) 
  20.  { 
  21.   $const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1); //獲取$consts中的一個隨機數 
  22.   $vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1); //獲取$vowels中的一個隨機數 
  23.  } 
  24.  $radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4]; 
  25.  $_SESSION['checkcode'] = $string = substr($radomstring,0,4); //顯示4個字符 
  26.  
  27.  $imageX = strlen($radomstring)*8; //圖像的寬 
  28.  $imageY = 20;      //圖像的高 
  29.  $im = imagecreatetruecolor($imageX,$imageY); //新建一個真彩色圖像 
  30.  
  31.  //creates two variables to store color 
  32.  $background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250)); //背景色 
  33.  $foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)), 
  34.   imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)), 
  35.   imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)), 
  36.   imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255)) 
  37.  ); 
  38.  $foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80); //分配顏色并說明透明度 
  39.  $middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160)); //中間背景 
  40.  $middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80); //中間背景2 
  41.  
  42.  //與左上角的顏色相同的都會被填充 
  43.  imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254)); 
  44.  //往圖像上寫入文字 
  45.  imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], 'C:WindowsFontsArial.ttf', $string[0]); 
  46.  imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], 'C:WindowsFontsArial.ttf', $string[1]); 
  47.  imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)],'C:WindowsFontsArial.ttf', $string[2]); 
  48.  imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)],'C:WindowsFontsArial.ttf', $string[3]); 
  49.  
  50.  //畫邊框 
  51.  $border = imagecolorallocate($im, 133, 153, 193); 
  52.  imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border); 
  53.  
  54.  //畫一些隨機出現的點 
  55.  $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255)); 
  56.  for ($i=0;$i<80;$i++) 
  57.  { 
  58.   imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol); 
  59.  } 
  60.  //畫隨機出現的線 
  61.  for ($x=0; $x<9;$x++) 
  62.  { 
  63.   if(mt_rand(0,$x)%2==0) 
  64.   { 
  65.    imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999)); //畫線 
  66.    imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2); //畫橢圓 
  67.   } 
  68.   else 
  69.   { 
  70.    imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999)); 
  71.    imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground); 
  72.   } 
  73.  } 
  74.  //output to browser 
  75.  header("content-type:image/pngrn"); 
  76.  imagepng($im); 
  77.  imagedestroy($im); 
  78. else 
  79.  $files = glob(XINCHENG_ROOT.'images/checkcode/*.jpg'); 
  80.  if(!is_array($files)) die('請檢查文件目錄完整性:/images/checkcode/'); 
  81.  
  82.  $checkcodefile = $files[rand(0, count($files)-1)]; //隨機其中一個文件 
  83.  $_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4); //獲得文件名 
  84.  
  85.  header("content-type:image/jpegrn"); 
  86.  include $checkcodefile; 
  87. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永春县| 上饶县| 抚顺市| 蚌埠市| 巴中市| 鸡西市| 佳木斯市| 贺兰县| 霍邱县| 乐业县| 锡林浩特市| 德阳市| 旬邑县| 萝北县| 贡嘎县| 杨浦区| 塘沽区| 湟中县| 色达县| 苍山县| 灌南县| 于田县| 吉水县| 贵南县| 芜湖县| 涡阳县| 宁德市| 定结县| 裕民县| 昔阳县| 扎鲁特旗| 滨州市| 玉环县| 信丰县| 大宁县| 墨玉县| 通海县| 冀州市| 佳木斯市| 铅山县| 壶关县|