专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » 验证码代码:PHP汉字验证码的实现代码 »正文

验证码代码:PHP汉字验证码的实现代码

来源: 发布时间:星期四, 2009年2月12日 浏览:226次 评论:0


    现在都流行搞汉字验证码了究其原因还是自动通过验证太多今天和大家探讨个PHP汉字验证码实现代码,中国自学编程网www.zxbc.cn 起来看看代码吧!

<?php       
$ChineseChar = .gif' />(\"人\",\"出\",\"来\",\"友\",\"学\",\"孝\",\"仁\",\"义\",\"礼\",\"廉\",\"忠\",\"国\",\"中\",\"易\",\"白\",\"者\",\"火 \",\"土\",\"金\",\"木\",\"雷\",\"风\",\"龙\",\"虎\",\"天\",\"地\",   \"生\",\"晕\",\"菜\",\"鸟\",\"田\",\" 3\",\"百\",\"钱\",\"福 \",\"爱\",\"情\",\"兽\",\"虫\",\"鱼\",\" 9\",\"网\",\"新\",\"度\",\"哎\",\"唉\",\"啊\",\"哦\",\"仪\",\"老\",\"少\",\"日\",   \"月 \",\"星\");    
?>    

<?php        
session_start;    
$errorMSG = ’’;    
//验证用户输入是否和验证码致    
(!is_null($_POST[’check’]))    
{    
        (strcmp($_SESSION[’code’],$_POST[’code’])0)    
            $errorMSG = \"<p style=\\\"font-size:12px;color:#009900\\\">验证成功!</p>\";    
            
            $errorMSG = \"<p style=\\\"font-size:12px;color:#FF0000\\\">验证失败!</p>\";    
}    
?>    
<html>    
<head>    
<meta http-equiv=\"Content-Type\" content=\"text/html; char=gb2312\">    
</head>    
<body>    
<?php    
($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    
_once(\"chinesechar.php\");    
session_start;     [Page]
// 设置 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[(.gif' />_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);    
?>

 

0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: