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

首頁(yè) > 語(yǔ)言 > PHP > 正文

利用php生成驗(yàn)證碼

2024-09-04 11:44:41
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
  1. <?php 
  2. /** 
  3.  * php生成<a href="http://m.survivalescaperooms.com/zhuanti/yanzhengma/" class="anchor" target="_blank">驗(yàn)證碼</a> 
  4.  * @param $width 畫布寬 
  5.  * @param $height 畫布高 
  6.  * @param $vcodelen 驗(yàn)證碼長(zhǎng)度 
  7.  * @param $pointnum 干擾像素點(diǎn)數(shù)量 
  8.  * @param $linenum 干擾線條數(shù)量 
  9.  * 
  10.  * 思路:創(chuàng)建驗(yàn)證碼畫布,生成并填充背景色,生成驗(yàn)證碼內(nèi)容/干擾像素點(diǎn)/線,填充到畫布,輸出。 
  11.  */ 
  12.  $width= 100; 
  13.  $height= 30; 
  14.  $vcodelen= 4; 
  15.  $pointnum= 200; 
  16.  $linenum= 3; 
  17.  // 創(chuàng)建畫布 
  18.  $image= imagecreatetruecolor($width,$height); 
  19.  // 創(chuàng)建色塊 
  20.  $bgcolor= imagecolorallocate($image, 255, 255, 255); 
  21.  // 填充畫布背景色 
  22.  imagefill($image, 0, 0,$bgcolor); 
  23.  // 驗(yàn)證碼內(nèi)容 
  24.  for($i=0;$i<$vcodelen;$i++) { 
  25.   // <a href="/tags.php/%D7%D6%CC%E5%B4%F3%D0%A1/" target="_blank">字體大小</a> 
  26.   $fontsize= 5; 
  27.   // 字體顏色,顏色在限定范圍內(nèi)隨機(jī) 
  28.   $fontcolor= imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120)); 
  29.   $data='abcdefghijklmnopqrstuvwxyz0123456789' 
  30.   // 驗(yàn)證碼內(nèi)容在以上字符串內(nèi)隨機(jī)截取 
  31.   $fontcontent=<a href="/tags.php/substr/" target="_blank">substr</a>($data, rand(0,strlen($data)),1); 
  32.   // 字符串顯示位置 
  33.   $x= ($i*$width/4)+rand(5,15); 
  34.   $y= rand(5,10); 
  35.   // 字符串填充圖片 
  36.   // imagestring的字體大小可選1-5,字體再大需要用imagettftext函數(shù)(需要字體文件) 
  37.   imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor); 
  38.   // imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, '/font/Geneva.dfont', $fontcontent); 
  39.  } 
  40.  // 干擾像素點(diǎn) 
  41.  for($i=0;$i<$pointnum;$i++) { 
  42.   $pointcolor= imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120)); 
  43.   // 畫布填充像素點(diǎn)函數(shù) 
  44.   imagesetpixel($image, rand(0,$width), rand(0,$height),$pointcolor); 
  45.  } 
  46.  // 干擾線條 
  47.  for($i=0;$i<$linenum;$i++) { 
  48.   $linecolor= imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120)); 
  49.   // 畫布填充線條函數(shù) 
  50.   imageline($image, rand(0,$width), rand(0,$height), rand(0,$width), rand(0,$height),$linecolor); 
  51.  } 
  52.  // 圖片輸出格式 
  53.  header('content-type: image/png'); 
  54.  // 輸出驗(yàn)證碼圖片 
  55.  imagepng($image); 
  56.  // 銷毀畫布 
  57.  imagedestroy($image); 
  58. ?> 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 佛冈县| 南雄市| 南平市| 法库县| 卢龙县| 松溪县| 宣恩县| 鄯善县| 民丰县| 金川县| 嘉鱼县| 广饶县| 桐庐县| 萝北县| 香港 | 盐亭县| 深州市| 桐梓县| 乐业县| 三穗县| 扎鲁特旗| 德江县| 阿勒泰市| 诏安县| 铅山县| 独山县| 西贡区| 金平| 汾阳市| 湘乡市| 天全县| 泽库县| 克山县| 临夏市| 威宁| 安宁市| 河津市| 洛南县| 上犹县| 略阳县| 鹤壁市|