国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 後端開發(fā) php教程 產(chǎn)生錯(cuò)綜複雜的(傾斜,正弦?guī)謹(jǐn)_線,粘貼,旋轉(zhuǎn)驗(yàn))證碼

產(chǎn)生錯(cuò)綜複雜的(傾斜,正弦?guī)謹(jǐn)_線,粘貼,旋轉(zhuǎn)驗(yàn))證碼

Mar 24, 2018 pm 05:52 PM
幹?jǐn)_

這次帶給大家生成錯(cuò)綜複雜的(傾斜,正弦?guī)謹(jǐn)_線,貼上,旋轉(zhuǎn)驗(yàn))證碼,生成錯(cuò)綜複雜的(傾斜,正弦?guī)謹(jǐn)_線,粘貼,旋轉(zhuǎn)驗(yàn))證碼的注意事項(xiàng)有哪些,以下就是實(shí)戰(zhàn)案例,一起來看一下。

現(xiàn)在好多網(wǎng)站使用的驗(yàn)證碼非常容易被軟體自動(dòng)辨識(shí)到,本文介紹了一種PHP產(chǎn)生複雜驗(yàn)證碼加入傾斜,弦?guī)謹(jǐn)_線,黏貼,旋轉(zhuǎn)等效果

常見的軟體不容易自動(dòng)辨識(shí)的驗(yàn)證碼做法有以下3種:

1、字型變型(一般透過演算法,進(jìn)行扭曲)

#2、字型黏貼(這裡面以qq驗(yàn)證碼代表了,目前網(wǎng)路上還是很難找到,破解qq驗(yàn)證碼的)

3 、幹?jǐn)_線,雜訊(這種辨識(shí)起來相當(dāng)容易,很容易被程式自動(dòng)化辨識(shí))

對(duì)於上面提到,第1,2 二種方法,在辨識(shí)時(shí)候,是比較困難的。

具體實(shí)作程式碼:

<?php
/**
 *帶文字旋轉(zhuǎn),傾斜,黏貼,加正弦干擾線驗(yàn)證碼*
 */
class Utils_Caption
{
	var $Width   = 60;      //圖片寬
	var $Height   = 30;      //圖片高
	var $Length   = 4;      //驗(yàn)證碼位數(shù)
	var $BgColor  = "#FFFFFF";  //背景色
	var $TFonts = array("font.ttf");
	var $TFontSize=array(17,20); //字體大小范圍
	var $TFontAngle=array(-20,20); //旋轉(zhuǎn)角度
	var $Chars  = "0123456789";     //驗(yàn)證碼范圍(字母數(shù)字)
	var $Code  = array();       //驗(yàn)證碼
	var $Image  = "";       //圖形對(duì)象
	var $FontColors=array(&#39;#f36161&#39;,&#39;#6bc146&#39;,&#39;#5368bd&#39;); //字體顏色,紅綠藍(lán)
	var $TPadden = 0.75;///字符間距,多少個(gè)字符
	var $Txbase = 5;///x軸兩邊距離
	var $Tybase =5 ;///y軸兩邊距離
	var $TLine =true; ///畫干擾線
	public function RandRSI() ///生成驗(yàn)證碼
	{
		$this->TFontAngle=range($this->TFontAngle[0],$this->TFontAngle[1]);
		$this->TFontSize=range($this->TFontSize[0],$this->TFontSize[1]);
		$arr=array();
		$Chars=$this->Chars;
		$TFontAngle=$this->TFontAngle;
		$TFontSize=$this->TFontSize;
		$FontColors=$this->FontColors;
		$code="";
		$font=dirname(FILE)."/font/".$this->TFonts[0];
		$charlen=strlen($Chars)-1;
		$anglelen=count($TFontAngle)-1;?//?角度范圍
		$fontsizelen=count($TFontSize)-1;?//?角度范圍
		$fontcolorlen=count($FontColors)-1;?//?角度范圍
		for($i=0;$i<$this->Length;$i++)?///得到字符與顏色
		{
			$char=$Chars[rand(0,$charlen)];?///得到字符
			$angle=$TFontAngle[rand(0,$anglelen)];?///旋轉(zhuǎn)角度
			$fontsize=$TFontSize[rand(0,$fontsizelen)];?///字體大小
			$fontcolor=$FontColors[rand(0,$fontcolorlen)];?///字體大小
			$bound=$this->_calculateTextBox($fontsize,$angle,$font,$char);?///得到范圍
			$arr[]=array($fontsize,$angle,$fontcolor,$char,$font,$bound);?///得到矩形框
			$code.=$char;
		}
		$this->Code=$arr;?//驗(yàn)證碼
		return?$code;
	}
	public?function?Draw()?///畫圖
	{
		if(empty($this->Code))?$this->RandRSI();
		$codes=$this->Code;?///用戶驗(yàn)證碼
		$wh=$this->_getImageWH($codes);
		$width=$wh[0];
		$height=$wh[1];?///高度
		$this->Width=$width;
		$this->Height=$height;
		$this->Image?=?imageCreate(?$width,?$height?);
		$image=$this->Image;
		$back?=?$this->_getColor2($this->_getColor(?$this->BgColor));?///背景顏色
		imageFilledRectangle($image,?0,?0,?$width,?$height,?$back);?///填充背景
		$TPadden=$this->TPadden;
		$basex=$this->Txbase;
		$color=null;
		foreach?($codes?as?$v)?///逐個(gè)畫字符
		{
			$bound=$v[5];
			$color=$this->_getColor2($this->_getColor($v[2]));
			imagettftext($image,?$v[0],?$v[1],?$basex,?$bound['height'],$color?,?$v[4],?$v[3]);
			$basex=$basex+$bound['width']*$TPadden-$bound['left'];///計(jì)算下一個(gè)左邊距
		}
		$this->TLine?$this->_wirteSinLine($color,$basex):null;?///畫干擾線
		header("Content-type:?image/png");
		imagepng(?$image);
		imagedestroy($image);
	}
	/**
	?*通過字體角度得到字體矩形寬度*
	?*
	?*?@param?int?$font_size?字體尺寸
	?*?@param?float?$font_angle?旋轉(zhuǎn)角度
	?*?@param?string?$font_file?字體文件路徑
	?*?@param?string?$text?寫入字符
	?*?@return?array?返回長(zhǎng)寬高
	?*/
	private?function?_calculateTextBox($font_size,?$font_angle,?$font_file,?$text)?{
		$box?=?imagettfbbox($font_size,?$font_angle,?$font_file,?$text);
		$min_x?=?min(array($box[0],?$box[2],?$box[4],?$box[6]));
		$max_x?=?max(array($box[0],?$box[2],?$box[4],?$box[6]));
		$min_y?=?min(array($box[1],?$box[3],?$box[5],?$box[7]));
		$max_y?=?max(array($box[1],?$box[3],?$box[5],?$box[7]));
		return?array(
		'left'?=>?($min_x?>=?-1)???-abs($min_x?+?1)?:?abs($min_x?+?2),
		'top'?=>?abs($min_y),
		'width'?=>?$max_x?-?$min_x,
		'height'?=>?$max_y?-?$min_y,
		'box'?=>?$box
		);
	}
	private?function?_getColor(?$color?)?//#ffffff
	{
		return?array(hexdec($color[1].$color[2]),hexdec($color[3].$color[4]),hexdec($color[5].$color[6]));
	}
	private?function?_getColor2(?$color?)?//#ffffff
	{
		return?imagecolorallocate?($this->Image,?$color[0],?$color[1],?$color[2]);
	}
	private?function?_getImageWH($data)
	{
		$TPadden=$this->TPadden;
		$w=$this->Txbase;
		$h=0;
		foreach?($data?as?$v)
		{
			$w=$w+$v[5]['width']*$TPadden-$v[5]['left'];
			$h=$h>$v[5]['height']?$h:$v[5]['height'];
		}
		return?array(max($w,$this->Width),max($h,$this->Height));
	}
	//畫正弦干擾線
	private?function?_wirteSinLine($color,$w)
	{
		$img=$this->Image;
		$h=$this->Height;
		$h1=rand(-5,5);
		$h2=rand(-1,1);
		$w2=rand(10,15);
		$h3=rand(4,6);
		for($i=-$w/2;$i<$w/2;$i=$i+0.1)
		{
			$y=$h/$h3*sin($i/$w2)+$h/2+$h1;
			imagesetpixel($img,$i+$w/2,$y,$color);
			$h2!=0?imagesetpixel($img,$i+$w/2,$y+$h2,$color):null;
		}
	}
}

DEMO程式碼:

$rsi = new Utils_Caption();
$rsi->TFontSize=array(15,17);
$rsi->Width=50;
$rsi->Height=25;
$code?=?$rsi->RandRSI();
session_start();
$_SESSION["CHECKCODE"]?=?$code;
$rsi->Draw();

運(yùn)行效果:

?

##大家可以修改程式碼中的對(duì)應(yīng)數(shù)值達(dá)到自己需要的複雜度

相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!

推薦閱讀:

php保留鍵值+合併數(shù)組詳解

#怎麼剔除二維數(shù)組中的重複的值

以上是產(chǎn)生錯(cuò)綜複雜的(傾斜,正弦?guī)謹(jǐn)_線,粘貼,旋轉(zhuǎn)驗(yàn))證碼的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

如何在PHP中實(shí)施身份驗(yàn)證和授權(quán)? 如何在PHP中實(shí)施身份驗(yàn)證和授權(quán)? Jun 20, 2025 am 01:03 AM

tosecurelyhandleauthenticationandationallizationInphp,lofterTheSesteps:1.AlwaysHashPasswordSwithPassword_hash()andverifyusingspasspassword_verify(),usepreparedStatatementStopreventsqlineptions,andStoreSeruserDatain usseruserDatain $ _sessiveferterlogin.2.implementrole-2.imaccessccsccccccccccccccccccccccccc.

我如何了解最新的PHP開發(fā)和最佳實(shí)踐? 我如何了解最新的PHP開發(fā)和最佳實(shí)踐? Jun 23, 2025 am 12:56 AM

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

什麼是PHP,為什麼它用於Web開發(fā)? 什麼是PHP,為什麼它用於Web開發(fā)? Jun 23, 2025 am 12:55 AM

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

如何設(shè)置PHP時(shí)區(qū)? 如何設(shè)置PHP時(shí)區(qū)? Jun 25, 2025 am 01:00 AM

tosetTherightTimeZoneInphp,restate_default_timezone_set()functionAtthestArtofyourscriptWithavalIdidentIdentifiersuchas'america/new_york'.1.usedate_default_default_timezone_set_set()

如何在操作系統(tǒng)(Windows,MacOS,Linux)上安裝PHP? 如何在操作系統(tǒng)(Windows,MacOS,Linux)上安裝PHP? Jun 20, 2025 am 01:02 AM

安裝PHP的方法因操作系統(tǒng)而異,以下是具體步驟:1.Windows用戶可使用XAMPP一鍵安裝包或手動(dòng)配置,下載XAMPP並安裝,選擇PHP組件或?qū)HP加入環(huán)境變量;2.macOS用戶可通過Homebrew安裝PHP,運(yùn)行相應(yīng)命令安裝並配置Apache服務(wù)器;3.Linux用戶(Ubuntu/Debian)可使用APT包管理器更新源後安裝PHP及常用擴(kuò)展,並通過創(chuàng)建測(cè)試文件驗(yàn)證安裝是否成功。

我如何驗(yàn)證PHP中的用戶輸入以確保其符合某些標(biāo)準(zhǔn)? 我如何驗(yàn)證PHP中的用戶輸入以確保其符合某些標(biāo)準(zhǔn)? Jun 22, 2025 am 01:00 AM

TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

如何使用session_destroy()在PHP中破壞會(huì)話? 如何使用session_destroy()在PHP中破壞會(huì)話? Jun 20, 2025 am 01:06 AM

要完全銷毀PHP中的會(huì)話,必須先調(diào)用session_start()啟動(dòng)會(huì)話,再調(diào)用session_destroy()刪除所有會(huì)話數(shù)據(jù)。 1.首先使用session_start()確保會(huì)話已啟動(dòng);2.然後調(diào)用session_destroy()清除會(huì)話數(shù)據(jù);3.可選但推薦:手動(dòng)unset$_SESSION數(shù)組以清除全局變量;4.同時(shí)刪除會(huì)話cookie,防止用戶保留會(huì)話狀態(tài);5.最後注意在銷毀後重定向用戶,並避免立即復(fù)用會(huì)話變量,否則需重新啟動(dòng)會(huì)話。這樣做能確保用戶徹底退出系統(tǒng),不留殘留信息。

什麼是php(serialize(),Unserialize())中的數(shù)據(jù)序列化? 什麼是php(serialize(),Unserialize())中的數(shù)據(jù)序列化? Jun 22, 2025 am 01:03 AM

thephpfunctionserize()andunSerialize()redustoconvertComplexdatStructDestoresToroStoroStoroSandaBackagagain.1.Serialize()

See all articles