當(dāng)前位置: 首頁IT技術(shù) → 關(guān)于PHP漢字驗證碼的實現(xiàn)代碼分享

關(guān)于PHP漢字驗證碼的實現(xiàn)代碼分享

更多
 本文章提供的是關(guān)于PHP漢字驗證碼的實現(xiàn)實例的代碼分享,希望對大家有用。

<?php
ChineseChar = array("人","出","來","友","學(xué)","孝","仁","義","禮","廉","忠","國","中","易","白","者","火 ","土","金","木","雷","風(fēng)","龍","虎","天","地", "生","暈","菜","鳥","田","三","百","錢","福 ","愛","情","獸","蟲","魚","九","網(wǎng)","新","度","哎","唉","啊","哦","儀","老","少","日", "月 ","星");
?>

<?php
session_start();
errorMSG = '';
//驗證用戶輸入是否和驗證碼一致
if(!is_null(_POST['check']))
{
if (strcasecmp(_SESSION['code'],_POST['code'])==0)
errorMSG = "<p style=\"font-size:12px;color:#009900\">驗證成功!</p>";
else
errorMSG = "<p style=\"font-size:12px;color:#FF0000\">驗證失敗!</p>";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<?php
if(errorMSG){
echo errorMSG;
}
?>
<form action=<?php echo _SERVER['PHP_SELF']?> method=post>
請輸入驗證碼:<input type="text" name="code" style="width:
80px"><img src="code.php">
<br>
<input type="submit" name="check" value="提交驗證碼">
</form>
</body>
</html>

<?php
include_once("chinesechar.php");
session_start();
// 設(shè)置 content-type
header("Content-type: image/png");
// 創(chuàng)建圖片
im = imagecreatetruecolor(120, 30);

// 創(chuàng)建顏色
fontcolor = imagecolorallocate(im, 255, 255, 255);
bg = imagecolorallocate(im, 0, 0, 0);

// 設(shè)置文字
for(i=0;i<4;i++) text .= ChineseChar[(array_rand(ChineseChar))];

_SESSION['code'] = text;
// 設(shè)置字體
font = 'simkai.ttf';

// 添加文字
imagettftext(im, 18, 0, 11, 21, fontcolor, font, iconv("GB2312","UTF-8",text));

// 輸出圖片
imagepng(im);
imagedestroy(im);
?>

熱門評論
最新評論
發(fā)表評論 查看所有評論(0)
昵稱:
表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
字?jǐn)?shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)