個人域名如何備案?公司域名如何備案?
988
2023-10-21
現在越來越多的網站都開始使用漢字驗證碼了,既增加了我們國人的親切感,同時也增加了機器破解的難度,這里我就簡單粗暴的說一下。。。
創建背景畫布
$image = imagecreatetruecolor(200, 60); $background = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $background);
畫干擾點
for ($i=0; $i < 300; $i++) { $pixColor = imagecolorallocate($image, rand(150, 240), rand(150, 240), rand(150, 240)); $pixX = rand(10, 190); $pixY = rand(5, 55); imagesetpixel($image, $pixX, $pixY, $pixColor); }
畫干擾線
//4條水平線 for ($i=0; $i < 5; $i++) { $lineColor = imagecolorallocate($image, rand(50, 150), rand(50, 150), rand(50, 150)); $lineX1 = 0; $lineX2 = 300; $lineY1 = ($i + 1) * 12; $lineY2 = ($i + 1) * 12; imageline($image, $lineX1, $lineY1, $lineX2, $lineY2, $lineColor); } //10條垂直線 for ($i=0; $i < 30; $i++) { $lineColor = imagecolorallocate($image, rand(50, 150), rand(50, 150), rand(50, 150)); $lineX1 = ($i + 1) * 10; $lineX2 = ($i + 1) * 10; $lineY1 = 0; $lineY2 = 60; imageline($image, $lineX1, $lineY1, $lineX2, $lineY2, $lineColor); }
畫漢字
$text = array('梔', '子', '花', '開'); for ($i=0; $i < 4; $i++) { $textColor = imagecolorallocate($image, rand(20, 100), rand(20, 100), rand(20, 100)); $textX = $i * 50 + 10; $textY = rand(40, 60); imagettftext($image, 30, rand(20, 50), $textX, $textY, $textColor, "/Library/Fonts/華文仿宋.ttf", $text[$i]); }
這里注意一下,字體文件一定要支持中文的
編碼要使用utf-8,gbk的中文記得要轉嗎【iconv函數可以幫助你】
輸出圖像
header("Content-Type:image/png"); imagepng($image);
銷毀資源
imagedestroy($image);
經過粗略的搞吧搞吧,中文驗證碼也就顯示出來了,當然一般網站使用的時候會有一個漢字庫種子,從里面隨機取出特定個數的漢字顯示,最后就是記錄到session進行驗證了。
以上所述就是本文的全部內容了,希望大家能夠喜歡。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!