《PHP學(xué)習(xí):PHP實現(xiàn)簡單漢字驗證碼》要點:
本文介紹了PHP學(xué)習(xí):PHP實現(xiàn)簡單漢字驗證碼,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP實例現(xiàn)在越來越多的網(wǎng)站都開始使用漢字驗證碼了,既增加了我們國人的親切感,同時也增加了機器破解的難度,這里我就簡單粗暴的說一下...
PHP實例創(chuàng)建配景畫布
PHP實例
$image = imagecreatetruecolor(200, 60);
$background = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $background);
PHP實例畫干擾點
PHP實例
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);
}
PHP實例畫干擾線
PHP實例
//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);
}
PHP實例畫漢字
PHP實例
$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]);
}
PHP實例這里注意一下,字體文件必定要支持中文的
PHP實例編碼要使用utf-8,gbk的中文記得要轉(zhuǎn)嗎【iconv函數(shù)可以贊助你】
PHP實例輸出圖像
PHP實例
header("Content-Type:image/png");
imagepng($image);
PHP實例銷毀資源
PHP實例
imagedestroy($image);
PHP實例經(jīng)過粗略的搞吧搞吧,中文驗證碼也就顯示出來了,當然一般網(wǎng)站使用的時候會有一個漢字庫種子,從里面隨機取出特定個數(shù)的漢字顯示,最后便是記錄到session進行驗證了.
PHP實例以上所述便是本文的全部內(nèi)容了,希望大家能夠喜歡.
《PHP學(xué)習(xí):PHP實現(xiàn)簡單漢字驗證碼》是否對您有啟發(fā),歡迎查看更多與《PHP學(xué)習(xí):PHP實現(xiàn)簡單漢字驗證碼》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/9404.html