解析PHP漢字驗(yàn)證碼的實(shí)現(xiàn)_PHP教程
推薦:php 截取中文?php ?php //截取中文字符串 function mysubstr(str, start, len) { tmpstr = ; strlen = start + len; for(i = 0; i strlen; i++) { if(ord(substr(str, i, 1)) 0xa0) { tmpstr .= substr(str, i, 2); i++; } else tmpstr .= substr(str, i, 1); } return
<?php
/*
* 文件:chinesechar.php
* 作用:漢字?jǐn)?shù)據(jù)儲(chǔ)存
* 作者:PHP實(shí)戰(zhàn)群:33918040 - 魚尾唯一
* 網(wǎng)址:http://bbs.ailf.cn/ http://www.fishwei.com/
* 特注:版權(quán)所有轉(zhuǎn)載注明出處!有付出才會(huì)有收獲!
*/
ChineseChar = array("人","出","來(lái)","友","學(xué)","孝","仁","義","禮","廉","忠","國(guó)","中","易","白","者","火 ","土","金","木","雷","風(fēng)","龍","虎","天","地", "生","暈","菜","鳥","田","三","百","錢","福 ","愛(ài)","情","獸","蟲","魚","九","網(wǎng)","新","度","哎","唉","啊","哦","儀","老","少","日", "月 ","星");
?>
<?php
session_start();
errorMSG = '';
//驗(yàn)證用戶輸入是否和驗(yàn)證碼一致
if(!is_null(_POST['check']))
{
if (strcasecmp(_SESSION['code'],_POST['code'])==0)
errorMSG = "<p style=\"font-size:12px;color:#009900\">驗(yàn)證成功!</p>";
else
errorMSG = "<p style=\"font-size:12px;color:#FF0000\">驗(yàn)證失敗!</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>
請(qǐng)輸入驗(yàn)證碼:<input type="text" name="code" style="width:
80px"><img src="code.php">
<br>
<input type="submit" name="check" value="提交驗(yàn)證碼">
</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);
?>
分享:淺析動(dòng)態(tài)網(wǎng)頁(yè)技術(shù)PHP中錯(cuò)誤處理的一些方法已經(jīng)玩php一段時(shí)間了,基本是from 0開(kāi)始的,經(jīng)常出現(xiàn)的問(wèn)題也很多,慢慢的可以熟練的查詢文檔了,而且,經(jīng)驗(yàn)也不是很多。 先look here。: error_reporting(1048);//1,2,4,7,...,1048 ob_start(); session_start(); date_default_timezone_set('Asia/Sh
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁(yè)面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問(wèn)控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語(yǔ)言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國(guó)語(yǔ)言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
- 相關(guān)鏈接:
- 教程說(shuō)明:
PHP教程-解析PHP漢字驗(yàn)證碼的實(shí)現(xiàn)。