解析PHP汉字验证码的实现_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
* 作用:汉字数据储存
* 作者:PHP实战群:33918040 - 鱼尾唯一
* 网址:http://bbs.ailf.cn/ http://www.fishwei.com/
* 特注:版权所有转载注明出处!有付出才会有收获!
*/
ChineseChar = array("人","出","来","友","学","孝","仁","义","礼","廉","忠","国","中","易","白","者","火 ","土","金","木","雷","风","龙","虎","天","地", "生","晕","菜","鸟","田","三","百","钱","福 ","爱","情","兽","虫","鱼","九","网","新","度","哎","唉","啊","哦","仪","老","少","日", "月 ","星");
?>
<?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();
// 设置 content-type
header("Content-type: image/png");
// 创建图片
im = imagecreatetruecolor(120, 30);
// 创建颜色
fontcolor = imagecolorallocate(im, 255, 255, 255);
bg = imagecolorallocate(im, 0, 0, 0);
// 设置文字
for(i=0;i<4;i++) text .= ChineseChar[(array_rand(ChineseChar))];
_SESSION['code'] = text;
// 设置字体
font = 'simkai.ttf';
// 添加文字
imagettftext(im, 18, 0, 11, 21, fontcolor, font, iconv("GB2312","UTF-8",text));
// 输出图片
imagepng(im);
imagedestroy(im);
?>
分享:浅析动态网页技术PHP中错误处理的一些方法已经玩php一段时间了,基本是from 0开始的,经常出现的问题也很多,慢慢的可以熟练的查询文档了,而且,经验也不是很多。 先look here。: error_reporting(1048);//1,2,4,7,...,1048 ob_start(); session_start(); date_default_timezone_set('Asia/Sh
- 相关链接:
- 教程说明:
PHP教程-解析PHP汉字验证码的实现。