Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 好久没来了,分享点东西顺便散分

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

Jun 23, 2016 pm 02:18 PM

本帖最后由 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,?上改之

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

1

<?PHP/** ?明:     Gif????建?   作者:     7di.net  QQ群:223494678  调用:     <img  src="/static/imghw/default1.png"  data-src="class_code.php?code=code"  class="lazy"   onclick="this.src=this.src+'&'+Math.round(Math.random(0)*1000)"   style="max-width:90%" alt="好久没来了,分享点东西顺便散分" >   验证:     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 '<pre class="brush:php;toolbar:false">',Var_Dump($Imdata),'

Copy after login
';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加油!

不解释!接分! 支持楼主

不错啊。。。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

See all articles