最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

非常實(shí)用的php驗(yàn)證碼類

 更新時(shí)間:2016年05月15日 09:07:55   作者:LoeYueng  
這篇文章主要為大家分享了非常實(shí)用的php驗(yàn)證碼類,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了php驗(yàn)證碼類,供大家參考,具體內(nèi)容如下

<?php 
/** 
 * 
 * @author Administrator 
 * 
 */ 
class ValidateCode{ 
   
  private $width; 
  private $height; 
  private $codeNum; 
  private $img_resouce; 
  private $disturbColorNum; 
  private $checkCode; 
   
  function __construct($width=80,$height=20,$codeNum=4) { 
    $this->width=$width; 
    $this->height=$height; 
    $this->codeNum=$codeNum; 
    $this->checkCode=$this->CreateCheckCode(); 
    $number=floor($width*$height/25); 
    if ($number>240-$codeNum) { 
      $this->disturbColorNum=240-$codeNum; 
    }else{ 
      $this->disturbColorNum=$number; 
    } 
  } 
   
  public function showImage($fontpath='') { 
    //創(chuàng)建圖像背景 
    $this->Img_resouce(); 
    //var_dump($img_resouce); 
    //設(shè)置干擾元素 
    $this->setDistructcolor(); 
    //向圖像中隨機(jī)畫出文本 
    $this->outputtext($fontpath); 
    //輸出圖像 
    $this->outputimage(); 
  } 
  /** 
   * 
   *獲取隨機(jī)創(chuàng)建的驗(yàn)證碼 
   */ 
  public function getCheckCode(){ 
     
  } 
  private function Img_resouce(){ 
    //創(chuàng)建一個(gè)真彩圖像 
    $this->img_resouce=imagecreatetruecolor($this->width,$this->height); 
    //隨機(jī)設(shè)置圖像背景 
    $backcolor=imagecolorallocate($this->img_resouce,rand(225,255),rand(225,255),rand(225,255)); 
    //填充顏色 
    imagefill($this->img_resouce, 0, 0, $backcolor); 
    //設(shè)置邊框背景 
    $border=imagecolorallocate($this->img_resouce, 0,0,0); 
    //畫一個(gè)矩形 
    imagerectangle($this->img_resouce,0,0,$this->width-1,$this->height-1,$border); 
  } 
  private function setDistructcolor(){ 
    //繪畫干擾點(diǎn) 
    for ($i = 0; $i <$this->disturbColorNum; $i++) { 
       
      imagesetpixel($this->img_resouce, rand(1, $this->width-2), rand(1, $this->height-2), rand(0,255)); 
    } 
     
    //繪畫干擾線 
    for ($j = 0; $j <3; $j++) { 
      $linecolor=imagecolorallocate($this->img_resouce,rand(0,255),rand(0,255),rand(0,255)); 
      imagearc($this->img_resouce, rand(0,$this->width), rand(0,$this->height), 
       rand(10, 225), rand(20, 150), 
       55, 44, $linecolor); 
    } 
  } 
  private function CreateCheckCode(){ 
    $code='23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ'; 
    $string=''; 
    for ($i = 0; $i < $this->codeNum; $i++) { 
       
      $char=$code{rand(0, strlen($code)-1)}; 
      $string.=$char; 
    } 
    return $string; 
  } 
  private function outputtext($fontpath=''){ 
    for ($i = 0; $i < $this->codeNum; $i++) { 
      $fontcolor=imagecolorallocate($this->img_resouce, rand(0,128), rand(0, 128), rand(0, 128)); 
      if ($fontpath=='') { 
         
         $fontsize=rand(3, 5); 
         $x=floor($this->width/$this->codeNum)*$i+3; 
         $y=rand(0, $this->height-20); 
         imagechar($this->img_resouce, $fontsize, $x, $y, $this->checkCode{$i}, $fontcolor); 
    }else{ 
         $fontsize=rand(12, 16); 
         $x=floor(($this->width-8)/$this->codeNum)*$i+8; 
         $y=rand($fontsize, $this->height-15); 
         imagettftext($this->img_resouce,$fontsize,rand(-45,45),$x,$y,$fontcolor,fontpath,$this->checkCode{$i}); 
       } 
    } 
  } 
  private function outputimage() { 
     
    if (imagetypes() & IMG_GIF) { 
      header("Content-type: image/gif"); 
      imagegif($this->img_resouce); 
    }else if(imagetypes() & IMG_JPEG) { 
      header("Content-type: image/jpeg"); 
      imagejpeg($this->img_resouce); 
    }else if(imagetypes() & IMG_PNG) { 
      header("Content-type: image/png"); 
      imagepng($this->img_resouce); 
    }else { 
      echo "PHP不支持的類型"; 
    } 
     
     
  } 
  private function __destruct(){ 
     
    imagedestroy($this->img_resouce); 
  } 
} 
?>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

  • PHP中3種生成XML文件方法的速度效率比較

    PHP中3種生成XML文件方法的速度效率比較

    實(shí)測(cè)結(jié)果不出所料,直接寫最快,耗時(shí)只有其他方式的1/3左右. 而其他2種方法差不多,相比之下SimpleXML要快一些
    2012-10-10
  • PHP的autoload機(jī)制的實(shí)現(xiàn)解析

    PHP的autoload機(jī)制的實(shí)現(xiàn)解析

    在使用PHP的OO模式開(kāi)發(fā)系統(tǒng)時(shí),通常大家習(xí)慣上將每個(gè)類的實(shí)現(xiàn)都存放在一個(gè)單獨(dú)的文件里,這樣會(huì)很容易實(shí)現(xiàn)對(duì)類進(jìn)行復(fù)用,同時(shí)將來(lái)維護(hù)時(shí)也很便利
    2012-09-09
  • lnmp安裝多版本PHP共存的方法詳解

    lnmp安裝多版本PHP共存的方法詳解

    這篇文章主要介紹了Lnmp環(huán)境中設(shè)置多版本PHP共存的技巧,依靠php-fpm工具來(lái)進(jìn)行管理,需要的朋友可以參考下
    2018-08-08
  • PHP 獲取ip地址代碼匯總

    PHP 獲取ip地址代碼匯總

    本文給大家匯總介紹了6種php獲取IP的方法,有簡(jiǎn)單有復(fù)雜,大家根據(jù)自己的項(xiàng)目需求,自由選擇吧。
    2015-07-07
  • php加速器eAccelerator的配置參數(shù)、API詳解

    php加速器eAccelerator的配置參數(shù)、API詳解

    eAccelerator是一個(gè)開(kāi)源PHP加速器,優(yōu)化程序,編碼器和動(dòng)態(tài)內(nèi)容緩存。它通過(guò)在編譯狀態(tài)下對(duì)它們進(jìn)行緩存以提高PHP腳本的性能,所以那些 系統(tǒng)開(kāi)銷在編譯時(shí)幾乎可以被消除
    2014-05-05
  • php 獲取mysql數(shù)據(jù)庫(kù)信息代碼

    php 獲取mysql數(shù)據(jù)庫(kù)信息代碼

    有時(shí)候我們需要知道m(xù)ysql數(shù)據(jù)庫(kù)中的一些情況,好在php提供了一些內(nèi)置方法與函數(shù),大家了解下了。
    2009-03-03
  • php截取字符串并保留完整xml標(biāo)簽的函數(shù)代碼

    php截取字符串并保留完整xml標(biāo)簽的函數(shù)代碼

    截取字符串并保留完整xml標(biāo)簽的php代碼,有需要的朋友可以參考下
    2013-02-02
  • PHP簡(jiǎn)單實(shí)現(xiàn)二維數(shù)組賦值與遍歷功能示例

    PHP簡(jiǎn)單實(shí)現(xiàn)二維數(shù)組賦值與遍歷功能示例

    這篇文章主要介紹了PHP簡(jiǎn)單實(shí)現(xiàn)二維數(shù)組賦值與遍歷功能,涉及php數(shù)組的簡(jiǎn)單賦值、遍歷、運(yùn)算、讀取等操作使用技巧,需要的朋友可以參考下
    2017-10-10
  • PHP基于curl實(shí)現(xiàn)模擬微信瀏覽器打開(kāi)微信鏈接的方法示例

    PHP基于curl實(shí)現(xiàn)模擬微信瀏覽器打開(kāi)微信鏈接的方法示例

    這篇文章主要介紹了PHP基于curl實(shí)現(xiàn)模擬微信瀏覽器打開(kāi)微信鏈接的方法,結(jié)合實(shí)例形式分析了php使用curl通過(guò)設(shè)置HTTP_USER_AGENT實(shí)現(xiàn)模擬微信瀏覽器相關(guān)操作技巧,需要的朋友可以參考下
    2019-02-02
  • 解決php-fpm.service not found問(wèn)題的辦法

    解決php-fpm.service not found問(wèn)題的辦法

    這篇文章主要給大家介紹了解決php-fpm.service not found問(wèn)題的辦法,文中詳細(xì)介紹的解決這個(gè)問(wèn)題的思路與過(guò)程,分享出來(lái)給大家,如果有同樣問(wèn)題的朋友就不用到處找解決辦法了,下面來(lái)一起看看吧。
    2017-06-06

最新評(píng)論

汝州市| 关岭| 台前县| 南投市| 惠东县| 白朗县| 育儿| 宾川县| 社会| 容城县| 黄浦区| 林口县| 清徐县| 武川县| 灵寿县| 清远市| 漳平市| 汾阳市| 海淀区| 托里县| 清流县| 博乐市| 黄浦区| 克东县| 永平县| 高邑县| 张家港市| 冀州市| 梁平县| 昌吉市| 孝昌县| 奉贤区| 上栗县| 平原县| 宁南县| 武邑县| 吉林市| 桑日县| 喀喇沁旗| 常熟市| 寿阳县|