使用PHP怎么實(shí)現(xiàn)一個(gè)漢字驗(yàn)證碼功能-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)使用PHP怎么實(shí)現(xiàn)一個(gè)漢字驗(yàn)證碼功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)建站專(zhuān)注于企業(yè)全網(wǎng)整合營(yíng)銷(xiāo)推廣、網(wǎng)站重做改版、延長(zhǎng)網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5開(kāi)發(fā)、商城網(wǎng)站制作、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性?xún)r(jià)比高,為延長(zhǎng)等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。

創(chuàng)建背景畫(huà)布


$image = imagecreatetruecolor(200, 60);
$background = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $background);

畫(huà)干擾點(diǎn)

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);
}

畫(huà)干擾線

//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);
}

畫(huà)漢字

$text = array('梔', '子', '花', '開(kāi)');
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的中文記得要轉(zhuǎn)嗎【iconv函數(shù)可以幫助你】

輸出圖像

header("Content-Type:image/png");
imagepng($image);

銷(xiāo)毀資源

imagedestroy($image);

經(jīng)過(guò)粗略的搞吧搞吧,中文驗(yàn)證碼也就顯示出來(lái)了,當(dāng)然一般網(wǎng)站使用的時(shí)候會(huì)有一個(gè)漢字庫(kù)種子,從里面隨機(jī)取出特定個(gè)數(shù)的漢字顯示,最后就是記錄到session進(jìn)行驗(yàn)證了。

看完上述內(nèi)容,你們對(duì)使用PHP怎么實(shí)現(xiàn)一個(gè)漢字驗(yàn)證碼功能有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

新聞標(biāo)題:使用PHP怎么實(shí)現(xiàn)一個(gè)漢字驗(yàn)證碼功能-創(chuàng)新互聯(lián)
本文路徑:http://www.muchs.cn/article28/dodejp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航網(wǎng)頁(yè)設(shè)計(jì)公司、Google、網(wǎng)站維護(hù)、云服務(wù)器、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)