热搜:NVER node 开发 php

好久没来了,分享点东西顺便散分

2024-09-20 17:30:01
好久没来了,分享点东西顺便散分

本帖最后由 sibang 于 2013-08-01 16:11:49 编辑

phpgif 会动 验证码 php gif ?片??? ??

纯PHP手工打造的  会动的多帧GIF图片验证码.
效果演示:http://pcik.7di.net/pcik_reg

百度的效果演示:https://passport.baidu.com/cgi-bin/genimage?captchaservice63636236364e55367233302f31673844526b664451665a5a4d4977466974376b707a754466777934697449455561625171346c725055444b51734a35376d2b4f744b6d303238315341382b354675344c3153745869487252376169752b437450515138574972436752584f53717849726f48593258666c373574593753614f4d32703831724e51722b694a31756b67467137644c30506979496639594e504931536732687a5a505379305544554245724f76694a307247632b4f76426165663144732b595359394950413470476453787865564f6b506e674f7537637264526d716541377a384b487445624f365a4774657a58502b7347703763696d5752614171615747784e5a6c5042336634766a5049766853365974444258577968645a4f654f55

由於我水平不行,所以做不到百度那??的效果,?海涵

验证码图片由PHP生成的多帧构成,所以验证码是一个真实存在的可以动的gif图
使用方法非常简单:
?明:
Gif????建?
作者:
7di.net  QQ群:223494678
调用:

验证:
IF(!isSet($_SESSION['code']) Or StrToLower($_SESSION['code'])!=StrToLower($cod)){
throw New Exception('Error:'.__LINE__.',?????!');Die();
}unSet($cod,$_SESSION['code']);

下载地址:http://download.csdn.net/detail/sibang/5852531

回复讨论(解决方案)

好物.....

支持一下  顺便接分

您的验证码文字都出现在第一帧,因此只是好玩而已

望改进!

看一眼拿点分

您的验证码文字都出现在第一帧,因此只是好玩而已

望改进!
?,?太?懂,希望斑竹老大??指?一下.


您的验证码文字都出现在第一帧,因此只是好玩而已

望改进!
?,?太?懂,希望斑竹老大??指?一下.
意思是不是验证码出现在了第一帧,因此破解验证码只要拿到第一帧即可,所以改进,不让他在第一帧出现。



您的验证码文字都出现在第一帧,因此只是好玩而已

望改进!
?,?太?懂,希望斑竹老大??指?一下.
意思是不是验证码出现在了第一帧,因此破解验证码只要拿到第一帧即可,所以改进,不让他在第一帧出现。
ok,?上改之

修改完毕,现在第一帧为干扰码,请众位指点:

<?PHP/**	?明:		Gif????建?	作者:		7di.net  QQ群:223494678	调用:			验证:		IF(!isSet($_SESSION['code']) Or StrToLower($_SESSION['code'])!=StrToLower($cod)){			throw New Exception('Error:'.__LINE__.',?????!');Die();		}unSet($cod,$_SESSION['code']);/**///ini_set('display_errors',True);//Error_reporting(E_ALL);$code=(isSet($_REQUEST['code'])) ? $_REQUEST['code'] : '';IF($code=='code'){	OB_start();OB_clean();	//设置SessionID	IF(!isSet($_SESSION)){Session_start();}	//GIF类	Class GIF{		Private Static $Txt='';			//GIF mess		Private Static $Img='GIF89a';	//GIF header 6 bytes		Private Static $Debug=False;	//Is open Debug?		Private Static $BUF=Array();		Private Static $LOP= 0;		Private Static $DIS= 2;		Private Static $COL=-1;		Private Static $IMG=-1;		/**			生成GIF图片验证			@param $W 宽度			@param $H 高度			@param $B 背景色		/**/		Public Static Function init($W=75,$H=25,$B=''){			$chars='bcdefhkmnrstuvwxyABCDEFGHKMNPRSTUVWXY34568';			For($i=0;$i<3;$i++){				self::$Txt .= SubStr($chars,mt_rand(0,strlen($chars)-1),1);			}unSet($chars);			$_SESSION['code']=StrToLower(self::$Txt);			// 记录session,全部小?			IF($B=='' Or StriStr($B,',')==False Or Substr_Count($B,',')!=2){$B='255,255,255';}			$B=Explode(',',$B);			//生成一个多帧的GIF动画			For($i=0;$i<7;$i++){				$Im=ImageCreate($W,$H);				//背景				$bg=ImageColorAllocate($Im,$B[0],$B[1],$B[2]);				ImageColorTransparent($Im,$bg);				unSet($bg);				IF($i==0) {//第一??干??					$txt=ImageColorAllocate($Im,35,35,35);						ImageTTFtext($Im,15,Rand(-15,25),5,($H-3),$txt,'class_code.ttf',self::$Txt[1]);						ImageTTFtext($Im,15,Rand(-10,20),21,($H-4),$txt,'class_code.ttf',self::$Txt[1]);						ImageTTFtext($Im,15,Rand(-25,15),38,($H-4),$txt,'class_code.ttf',self::$Txt[1]);					unSet($txt);				}Else{//???					$txt=ImageColorAllocate($Im,35,35,35);						//ImageString($Im,7,Rand(0,($W/2)),Rand(-3,5),self::$Txt,$txt);						ImageTTFtext($Im,15,Rand(-15,25),5,($H-3),$txt,'class_code.ttf',self::$Txt[0]);						ImageTTFtext($Im,15,Rand(-10,20),21,($H-4),$txt,'class_code.ttf',self::$Txt[1]);						ImageTTFtext($Im,15,Rand(-25,15),38,($H-4),$txt,'class_code.ttf',self::$Txt[2]);					unSet($txt);				}				ImageGif($Im);Imagedestroy($Im);				$Imdata[]=ob_get_contents();				OB_clean();			}unSet($W,$H,$B);			IF(self::$Debug){Echo '
',Var_Dump($Imdata),'
';Die();} Header('Content-type:image/gif'); Return GIF::CreatGif($Imdata,20); unSet($Imdata); } Private Static Function CreatGif($GIF_src,$GIF_dly=10,$GIF_lop=0,$GIF_dis=0,$GIF_red=0,$GIF_grn=0,$GIF_blu=0,$GIF_mod='bin'){ IF(!is_array($GIF_src) && !is_array($GIF_tim)){ throw New Exception('Error:'.__LINE__.',Does not supported function for only one image!!');Die(); } self::$LOP=($GIF_lop>-1) ? $GIF_lop : 0; self::$DIS=($GIF_dis>-1) ? (($GIF_dis<3) ? $GIF_dis : 3) : 2; self::$COL=($GIF_red>-1 && $GIF_grn>-1 && $GIF_blu>-1) ? ($GIF_red | ($GIF_grn << 8) | ($GIF_blu << 16)) : -1; For($i=0,$src_count=count($GIF_src);$i<$src_count;$i++){ IF(strToLower($GIF_mod) == 'url'){ self::$BUF[]=fread(fopen($GIF_src[$i],'rb'),filesize($GIF_src[$i])); }Elseif(strToLower($GIF_mod) == 'bin'){ self::$BUF[]=$GIF_src[$i]; }Else{ throw New Exception('Error:'.__LINE__.',Unintelligible flag ('.$GIF_mod.')!');Die(); } IF(!(Substr(self::$BUF[$i],0,6)=='GIF87a' Or Substr(self::$BUF[$i],0,6)=='GIF89a')){ throw New Exception('Error:'.__LINE__.',Source '.$i.' is not a GIF image!');Die(); } For($j=(13+3*(2 << (ord(self::$BUF[$i]{10})& 0x07))),$k=TRUE;$k;$j++){ switch(self::$BUF[$i]{$j}){ case '!': IF((substr(self::$BUF[$i],($j+3),8))== 'NETSCAPE'){ throw New Exception('Error:'.__LINE__.',Could not make animation from animated GIF source ('.($i+1).')!');Die(); } break; case ';': $k=FALSE; break; } } } GIF::AddHeader(); For($i=0,$count_buf=count(self::$BUF);$i<$count_buf;$i++){ GIF::AddFrames($i,$GIF_dly); } self::$Img .= ';'; Return (self::$Img); } Private Static Function AddHeader(){ $i=0; IF(ord(self::$BUF[0]{10}) & 0x80){ $i=3*(2 << (ord(self::$BUF[0]{10}) & 0x07)); self::$Img .= substr(self::$BUF[0],6,7); self::$Img .= substr(self::$BUF[0],13,$i); self::$Img .= "!\377\13NETSCAPE2.0\3\1".chr(self::$LOP & 0xFF).chr((self::$LOP >> 8) & 0xFF)."\0"; }unSet($i); } Private Static Function AddFrames($i,$d){ $L_str=13+3*(2 <<(ord(self::$BUF[$i]{10}) & 0x07)); $L_end=strlen(self::$BUF[$i])-$L_str-1; $L_tmp=substr(self::$BUF[$i],$L_str,$L_end); $G_len=2 << (ord(self::$BUF[0]{10}) & 0x07); $L_len=2 << (ord(self::$BUF[$i]{10}) & 0x07); $G_rgb=substr(self::$BUF[0],13,3*(2 << (ord(self::$BUF[0]{10}) & 0x07))); $L_rgb=substr(self::$BUF[$i],13,3*(2 << (ord(self::$BUF[$i]{10}) & 0x07))); $L_ext="!\xF9\x04".chr((self::$DIS << 2)+ 0).chr(($d >> 0) & 0xFF).chr(($d >> 8) & 0xFF)."\x0\x0"; IF(self::$COL>-1 && ord(self::$BUF[$i]{10}) & 0x80){ For($j=0;$j<(2 << (ord(self::$BUF[$i]{10}) & 0x07));$j++){ IF(ord($L_rgb{3*$j+0})==(self::$COL >> 0) & 0xFF && ord($L_rgb{3*$j+1})== (self::$COL >> 8) & 0xFF && ord($L_rgb{3*$j+2}) == (self::$COL >> 16) & 0xFF){ $L_ext="!\xF9\x04".chr((self::$DIS << 2)+1).chr(($d >> 0) & 0xFF).chr(($d >> 8) & 0xFF).chr($j)."\x0"; break; } } } switch($L_tmp{0}){ case '!': $L_img=substr($L_tmp,8,10); $L_tmp=substr($L_tmp,18,strlen($L_tmp)-18); break; case ',': $L_img=substr($L_tmp,0,10); $L_tmp=substr($L_tmp,10,strlen($L_tmp)-10); break; } IF(ord(self::$BUF[$i]{10}) & 0x80 && self::$IMG>-1){ IF($G_len == $L_len){ IF(GIF::Compare($G_rgb,$L_rgb,$G_len)){ self::$Img .= ($L_ext.$L_img.$L_tmp); }Else{ $byte =ord($L_img{9}); $byte |= 0x80; $byte &= 0xF8; $byte |= (ord(self::$BUF[0]{10}) & 0x07); $L_img{9}=chr($byte); self::$Img .= ($L_ext.$L_img.$L_rgb.$L_tmp); } }Else{ $byte =ord($L_img{9}); $byte |= 0x80; $byte &= 0xF8; $byte |= (ord(self::$BUF[$i]{10}) & 0x07); $L_img{9}=chr($byte); self::$Img .= ($L_ext.$L_img.$L_rgb.$L_tmp); } }Else{ self::$Img .= ($L_ext.$L_img.$L_tmp); } self::$IMG =1; } Private Static Function Compare($G_Block,$L_Block,$Len){ For($i=0;$i<$Len;$i++){ IF($G_Block{3*$i+0} != $L_Block{3*$i+0} || $G_Block{3*$i+1} != $L_Block{3*$i+1} || $G_Block{3*$i+2} != $L_Block{3*$i+2}){ Return (0); } } Return (1); } } //取得自定?背景色 $bgcolor=(isSet($_REQUEST['c'])) ? $_REQUEST['c'] : ''; //?出GIF Echo Gif::init(60,23,$bgcolor); Die();}

对我这种新手来说,这个是好东西啊!果断收藏。

我果断收藏它

我果断收藏它 嘿嘿

不错,收藏了

谢啦,学习了

接分 

不错不错, 改进下更好

很好很强大!!

收藏了  以后多交流

lz加油!

不解释!接分! 支持楼主

不错啊。。。