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

首頁 > 語言 > PHP > 正文

實用的一個php驗證碼類

2024-09-04 11:44:07
字體:
來源:轉載
供稿:網友
  1. <?php
  2. class ImageCode{ 
  3.  private $width;//驗證碼圖片寬度 
  4.  private $height;//驗證碼圖片高度 
  5.  private $codeNum;//驗證碼字符個數 
  6.  private $checkCode;//驗證碼字符 
  7.  private $image;//驗證碼畫布 
  8.  function __construct($width=60,$height=20,$codeNum=4){ 
  9.   $this->width=$width
  10.   $this->height=$height
  11.   $this->codeNum=$codeNum
  12.   $this->checkCode=$this->createCheckCode(); 
  13.  } 
  14.   
  15.  function getcreateImage(){ 
  16.   $this->getcreateImage(); 
  17.   $this->outputText(); 
  18.   $this->setDisturbColor(); 
  19.   $this->outputImage(); 
  20.  } 
  21.  function getCheckCode(){ 
  22.   return $this->checkCode; 
  23.  } 
  24.   
  25.  private function getCreateImage(){ 
  26.   $this->image=imagecreatetruecolor($this->width,$this->height); 
  27.   $black=imagecolorallocate($this->image,255,255,255,0); 
  28.   $border=imagecolorallocate($this->image,255,255,255,255); 
  29.   imagefilledrectangle($this->image,0,0,$this->width-1,$this->height-1,$border); 
  30.  } 
  31.  
  32.  private function createCheckCode(){ 
  33.   for($i=0;$i<$this->codeNum;$i){ 
  34.    $number=rand(0,2); 
  35.    switch($number){ 
  36.     case 0: 
  37.      $rand_number=rand(48,57);//數字 
  38.      break
  39.     case 1: 
  40.      $rand_number=rand(65,90);//大寫字母 
  41.      break
  42.     case 2: 
  43.      $rand_number=rand(97,122); 
  44.      break
  45.    } 
  46.    $asc=sprintf("%c",$rand_number); 
  47.    $asc_number=$asc_number.$asc
  48.   } 
  49.   return $asc_number
  50.  } 
  51.  
  52.  private function setDisturbColor(){ 
  53.   for($i=0;$i<=100;$i++){ 
  54.    $color=imagecolorallocate($this->image,255,255,255); 
  55.    imagesetpixel($this->image,rand(1,$this->width-2),rand(1,$this->height-2),$color); 
  56.   } 
  57.  } 
  58.  
  59.  private function outputImage(){ 
  60.   if(imagetypes()&IMG_GIF){ 
  61.    header("Content_type:image/gif"); 
  62.    imagegif($this->image); 
  63.   }elseif(imagetypes()&IMG_JGP){ 
  64.    header("Content_type:image/jpeg"); 
  65.    imagejpeg($this->image,"",0.5); 
  66.   }else{//開源代碼Vevb.com 
  67.    die("PHP不支持圖像創建"); 
  68.   } 
  69.  } 
  70.  
  71.  function __destruct(){ 
  72.   imagedestroy($this->image); 
  73.  } 
  74.  
  75. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泰州市| 鄂托克前旗| 朝阳区| 大连市| 麦盖提县| 师宗县| 丹江口市| 司法| 汝南县| 北安市| 宜昌市| 万盛区| 仁寿县| 绍兴县| 峨眉山市| 会同县| 武威市| 湟中县| 黎川县| 太白县| 西峡县| 中山市| 来安县| 肇庆市| 托克托县| 潞城市| 天峨县| 凉城县| 石门县| 瑞安市| 日土县| 大同县| 新乐市| 福安市| 宁海县| 丹东市| 威宁| 永福县| 乌拉特后旗| 多伦县| 乡宁县|