這次帶給大家生成錯綜複雜的(傾斜,正弦幹擾線,貼上,旋轉驗)證碼,生成錯綜複雜的(傾斜,正弦幹擾線,粘貼,旋轉驗)證碼的注意事項有哪些,以下就是實戰案例,一起來看一下。
現在好多網站使用的驗證碼非常容易被軟體自動辨識到,本文介紹了一種PHP產生複雜驗證碼加入傾斜,弦幹擾線,黏貼,旋轉等效果
常見的軟體不容易自動辨識的驗證碼做法有以下3種:
1、字型變型(一般透過演算法,進行扭曲)
#2、字型黏貼(這裡面以qq驗證碼代表了,目前網路上還是很難找到,破解qq驗證碼的)
3 、幹擾線,雜訊(這種辨識起來相當容易,很容易被程式自動化辨識)
對於上面提到,第1,2 二種方法,在辨識時候,是比較困難的。
具體實作程式碼:
<?php /** *带文字旋转,倾斜,黏贴,加正弦干扰线验证码* */ class Utils_Caption { var $Width = 60; //图片宽 var $Height = 30; //图片高 var $Length = 4; //验证码位数 var $BgColor = "#FFFFFF"; //背景色 var $TFonts = array("font.ttf"); var $TFontSize=array(17,20); //字体大小范围 var $TFontAngle=array(-20,20); //旋转角度 var $Chars = "0123456789"; //验证码范围(字母数字) var $Code = array(); //验证码 var $Image = ""; //图形对象 var $FontColors=array('#f36161','#6bc146','#5368bd'); //字体颜色,红绿蓝 var $TPadden = 0.75;///字符间距,多少个字符 var $Txbase = 5;///x轴两边距离 var $Tybase =5 ;///y轴两边距离 var $TLine =true; ///画干扰线 public function RandRSI() ///生成验证码 { $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;$iLength;$i++) ///得到字符与颜色 { $char=$Chars[rand(0,$charlen)]; ///得到字符 $angle=$TFontAngle[rand(0,$anglelen)]; ///旋转角度 $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; //验证码 return $code; } public function Draw() ///画图 { if(empty($this->Code)) $this->RandRSI(); $codes=$this->Code; ///用户验证码 $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) ///逐个画字符 { $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'];///计算下一个左边距 } $this->TLine?$this->_wirteSinLine($color,$basex):null; ///画干扰线 header("Content-type: image/png"); imagepng( $image); imagedestroy($image); } /** *通过字体角度得到字体矩形宽度* * * @param int $font_size 字体尺寸 * @param float $font_angle 旋转角度 * @param string $font_file 字体文件路径 * @param string $text 写入字符 * @return array 返回长宽高 */ 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<p style="text-align: left;">DEMO程式碼:</p><pre class="brush:php;toolbar:false">$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();
運行效果:
以上是產生錯綜複雜的(傾斜,正弦幹擾線,粘貼,旋轉驗)證碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

phpIdentifiesauser'ssessionSessionSessionCookiesAndSessionId.1)whiwsession_start()被稱為,phpgeneratesainiquesesesessionIdStoredInacookInAcookInAcienamedInAcienamedphpsessIdontheuser'sbrowser'sbrowser.2)thisIdallowSphptpptpptpptpptpptpptpptoretoreteretrieetrieetrieetrieetrieetrieetreetrieetrieetrieetrieetremthafromtheserver。

PHP會話的安全可以通過以下措施實現:1.使用session_regenerate_id()在用戶登錄或重要操作時重新生成會話ID。 2.通過HTTPS協議加密傳輸會話ID。 3.使用session_save_path()指定安全目錄存儲會話數據,並正確設置權限。

phpsessionFilesArestoredIntheDirectorySpecifiedBysession.save_path,通常是/tmponunix-likesystemsorc:\ windows \ windows \ temponwindows.tocustomizethis:tocustomizEthis:1)useession_save_save_save_path_path()

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

利用會話構建高效購物車系統的步驟包括:1)理解會話的定義與作用,會話是服務器端的存儲機制,用於跨請求維護用戶狀態;2)實現基本的會話管理,如添加商品到購物車;3)擴展到高級用法,支持商品數量管理和刪除;4)優化性能和安全性,通過持久化會話數據和使用安全的會話標識符。

本文討論了PHP中的crypt()和password_hash()的差異,以進行密碼哈希,重點介紹其實施,安全性和對現代Web應用程序的適用性。

文章討論了通過輸入驗證,輸出編碼以及使用OWASP ESAPI和HTML淨化器之類的工具來防止PHP中的跨站點腳本(XSS)。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版
好用的JavaScript開發工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

禪工作室 13.0.1
強大的PHP整合開發環境