非常實(shí)用的php驗(yàn)證碼類(lèi)
本文實(shí)例為大家分享了php驗(yàn)證碼類(lèi),供大家參考,具體內(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ī)畫(huà)出文本 $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); //畫(huà)一個(gè)矩形 imagerectangle($this->img_resouce,0,0,$this->width-1,$this->height-1,$border); } private function setDistructcolor(){ //繪畫(huà)干擾點(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)); } //繪畫(huà)干擾線 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不支持的類(lèi)型"; } } private function __destruct(){ imagedestroy($this->img_resouce); } } ?>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
- 一個(gè)漂亮的php驗(yàn)證碼類(lèi)(分享)
- PHP驗(yàn)證碼類(lèi)代碼( 最新修改,完全定制化! )
- 一個(gè)經(jīng)典的PHP驗(yàn)證碼類(lèi)分享
- 分享一個(gè)漂亮的php驗(yàn)證碼類(lèi)
- PHP實(shí)現(xiàn)簡(jiǎn)單實(shí)用的驗(yàn)證碼類(lèi)
- 一個(gè)簡(jiǎn)單安全的PHP驗(yàn)證碼類(lèi) 附調(diào)用方法
- PHP驗(yàn)證碼類(lèi)ValidateCode解析
- 一個(gè)簡(jiǎn)單安全的PHP驗(yàn)證碼類(lèi)、PHP驗(yàn)證碼
- PHP實(shí)現(xiàn)適用于自定義的驗(yàn)證碼類(lèi)
- PHP編寫(xiě)的圖片驗(yàn)證碼類(lèi)文件分享
- 一個(gè)實(shí)用的php驗(yàn)證碼類(lèi)
相關(guān)文章
php外部執(zhí)行命令函數(shù)用法小結(jié)
這篇文章主要介紹了php外部執(zhí)行命令函數(shù)用法,結(jié)合實(shí)例形式分析了exec與system執(zhí)行外部命令的相關(guān)使用技巧,需要的朋友可以參考下2016-10-10攻克CakePHP(PHP中的Ruby On Rails框架)圖文介紹
CakePHP框架實(shí)例介紹分析。圖文并茂2008-10-10dede3.1分頁(yè)文字采集過(guò)濾規(guī)則詳說(shuō)(圖文教程)續(xù)二
dede3.1分頁(yè)文字采集過(guò)濾規(guī)則詳說(shuō)(圖文教程)續(xù)二...2007-04-04Warning:?require():?open_basedir?restriction?in?effect,
在linux服務(wù)器部署thinkphp5的時(shí)候PHP報(bào)了Warning:?require():?open_basedir?restriction?in?effect這個(gè)錯(cuò)誤,是因?yàn)榫W(wǎng)站目錄配置錯(cuò)誤,PHP不能引入其授權(quán)目錄上級(jí)及其以上的文件。下面詳細(xì)講解如何處理這個(gè)問(wèn)題,需要的朋友可以參考下2022-11-11PHP獲取和操作配置文件php.ini的幾個(gè)函數(shù)介紹
當(dāng)你沒(méi)辦法修改php.ini配置文件怎么辦,沒(méi)事,php有一套設(shè)置和獲取配置信息的函數(shù)2013-06-06PHP依賴(lài)注入(DI)和控制反轉(zhuǎn)(IoC)詳解
這篇文章主要介紹了PHP依賴(lài)注入(DI)和控制反轉(zhuǎn)(IoC)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06