<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post//</link>
<title><![CDATA[PHP汉字验证码的实现]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Tue, 21 Aug 2007 15:36:14 +0000</pubDate> 
<guid>https://blog.liuts.com/post//</guid> 
<description>
<![CDATA[ 
	<textarea name="code" class="php" rows="15" cols="100">
<?php&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp;&nbsp;&nbsp;&nbsp;
* 文件:chinesechar.php&nbsp;&nbsp;&nbsp;&nbsp;
* 作用:汉字数据储存&nbsp;&nbsp;&nbsp;&nbsp;
* 作者:PHP实战群:33918040 - 鱼尾唯一&nbsp;&nbsp;&nbsp;&nbsp;
* 网址:http://bbs.ailf.cn/ http://www.fishwei.com/&nbsp;&nbsp;
* 特注:版权所有转载注明出处!有付出才会有收获! 
*/&nbsp;&nbsp;&nbsp;&nbsp;
$ChineseChar = array("人","出","来","友","学","孝","仁","义","礼","廉","忠","国","中","易","白","者","火 ","土","金","木","雷","风","龙","虎","天","地",&nbsp;&nbsp; "生","晕","菜","鸟","田","三","百","钱","福 ","爱","情","兽","虫","鱼","九","网","新","度","哎","唉","啊","哦","仪","老","少","日",&nbsp;&nbsp; "月 ","星");&nbsp;&nbsp;&nbsp;&nbsp;
?>&nbsp;&nbsp;&nbsp;&nbsp;

<?php&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp;&nbsp;&nbsp;&nbsp;
* 文件:check.php&nbsp;&nbsp;&nbsp;&nbsp;
* 作用:验证&nbsp;&nbsp;&nbsp;&nbsp;
* 作者:PHP实战群:33918040 - 鱼尾唯一&nbsp;&nbsp;&nbsp;&nbsp;
* 网址:http://bbs.ailf.cn/ http://www.fishwei.com/&nbsp;&nbsp; 
* 特注:版权所有转载注明出处!有付出才会有收获! 
*/&nbsp;&nbsp;&nbsp;&nbsp;
session_start();&nbsp;&nbsp;&nbsp;&nbsp;
$errorMSG = '';&nbsp;&nbsp;&nbsp;&nbsp;
//验证用户输入是否和验证码一致&nbsp;&nbsp;&nbsp;&nbsp;
if(!is_null($_POST['check']))&nbsp;&nbsp;&nbsp;&nbsp;
&#123;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (strcasecmp($_SESSION['code'],$_POST['code'])==0)&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errorMSG = "<p style=&#92;"font-size:12px;color:#009900&#92;">验证成功!</p>";&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errorMSG = "<p style=&#92;"font-size:12px;color:#FF0000&#92;">验证失败!</p>";&nbsp;&nbsp;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;&nbsp;&nbsp;
?>&nbsp;&nbsp;&nbsp;&nbsp;
<html>&nbsp;&nbsp;&nbsp;&nbsp;
<head>&nbsp;&nbsp;&nbsp;&nbsp;
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">&nbsp;&nbsp;&nbsp;&nbsp;
</head>&nbsp;&nbsp;&nbsp;&nbsp;
<body>&nbsp;&nbsp;&nbsp;&nbsp;
<?php&nbsp;&nbsp;&nbsp;&nbsp;
if($errorMSG)&#123;&nbsp;&nbsp;&nbsp;&nbsp;
echo $errorMSG;&nbsp;&nbsp;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;&nbsp;&nbsp;
?>&nbsp;&nbsp;&nbsp;&nbsp;
<form action=<?php echo $_SERVER['PHP_SELF']?> method=post>&nbsp;&nbsp;&nbsp;&nbsp;
请输入验证码：<input type="text" name="code" style="width:&nbsp;&nbsp;&nbsp;&nbsp;
80px"><img src="code.php">&nbsp;&nbsp;&nbsp;&nbsp;
<?php&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp;&nbsp;&nbsp;&nbsp;
* 文件:chinesechar.php&nbsp;&nbsp;&nbsp;&nbsp;
* 作用:汉字数据储存&nbsp;&nbsp;&nbsp;&nbsp;
* 作者:PHP实战群:33918040 - 鱼尾唯一&nbsp;&nbsp;&nbsp;&nbsp;
* 网址:http://bbs.ailf.cn/ http://www.fishwei.com/&nbsp;&nbsp;
* 特注:版权所有转载注明出处!有付出才会有收获! 
*/&nbsp;&nbsp;&nbsp;&nbsp;
$ChineseChar = array("人","出","来","友","学","孝","仁","义","礼","廉","忠","国","中","易","白","者","火 ","土","金","木","雷","风","龙","虎","天","地",&nbsp;&nbsp; "生","晕","菜","鸟","田","三","百","钱","福 ","爱","情","兽","虫","鱼","九","网","新","度","哎","唉","啊","哦","仪","老","少","日",&nbsp;&nbsp; "月 ","星");&nbsp;&nbsp;&nbsp;&nbsp;
?>&nbsp;&nbsp;&nbsp;&nbsp;

<?php&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp;&nbsp;&nbsp;&nbsp;
* 文件:check.php&nbsp;&nbsp;&nbsp;&nbsp;
* 作用:验证&nbsp;&nbsp;&nbsp;&nbsp;
* 作者:PHP实战群:33918040 - 鱼尾唯一&nbsp;&nbsp;&nbsp;&nbsp;
* 网址:http://bbs.ailf.cn/ http://www.fishwei.com/&nbsp;&nbsp; 
* 特注:版权所有转载注明出处!有付出才会有收获! 
*/&nbsp;&nbsp;&nbsp;&nbsp;
session_start();&nbsp;&nbsp;&nbsp;&nbsp;
$errorMSG = '';&nbsp;&nbsp;&nbsp;&nbsp;
//验证用户输入是否和验证码一致&nbsp;&nbsp;&nbsp;&nbsp;
if(!is_null($_POST['check']))&nbsp;&nbsp;&nbsp;&nbsp;
&#123;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (strcasecmp($_SESSION['code'],$_POST['code'])==0)&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errorMSG = "<p style=&#92;"font-size:12px;color:#009900&#92;">验证成功!</p>";&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$errorMSG = "<p style=&#92;"font-size:12px;color:#FF0000&#92;">验证失败!</p>";&nbsp;&nbsp;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;&nbsp;&nbsp;
?>&nbsp;&nbsp;&nbsp;&nbsp;
<html>&nbsp;&nbsp;&nbsp;&nbsp;
<head>&nbsp;&nbsp;&nbsp;&nbsp;
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">&nbsp;&nbsp;&nbsp;&nbsp;
</head>&nbsp;&nbsp;&nbsp;&nbsp;
<body>&nbsp;&nbsp;&nbsp;&nbsp;
<?php&nbsp;&nbsp;&nbsp;&nbsp;
if($errorMSG)&#123;&nbsp;&nbsp;&nbsp;&nbsp;
echo $errorMSG;&nbsp;&nbsp;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;&nbsp;&nbsp;
?>&nbsp;&nbsp;&nbsp;&nbsp;
<form action=<?php echo $_SERVER['PHP_SELF']?> method=post>&nbsp;&nbsp;&nbsp;&nbsp;
请输入验证码：<input type="text" name="code" style="width:&nbsp;&nbsp;&nbsp;&nbsp;
80px"><img src="code.php">&nbsp;&nbsp;&nbsp;&nbsp;
<br/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" name="check" value="提交验证码">&nbsp;&nbsp;&nbsp;&nbsp;
</form>&nbsp;&nbsp;&nbsp;&nbsp;
</body>&nbsp;&nbsp;&nbsp;&nbsp;
</html>&nbsp;&nbsp;&nbsp;&nbsp;

<?php&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp;&nbsp;&nbsp;&nbsp;
* 文件:code.php&nbsp;&nbsp;&nbsp;&nbsp;
* 作用:验证码生成&nbsp;&nbsp;&nbsp;&nbsp;
* 作者:PHP实战群:33918040 - 鱼尾唯一&nbsp;&nbsp;&nbsp;&nbsp;
* 网址:http://bbs.ailf.cn/ http://www.fishwei.com/&nbsp;&nbsp;&nbsp;&nbsp;
* 特注:由 没牙的草 指导 版权所有转载注明出处!有付出才会有收获!&nbsp;&nbsp;
*/&nbsp;&nbsp;&nbsp;&nbsp;
include_once("chinesechar.php");&nbsp;&nbsp;&nbsp;&nbsp;
session_start();&nbsp;&nbsp;&nbsp;&nbsp;
// 设置 content-type&nbsp;&nbsp;&nbsp;&nbsp;
header("Content-type: image/png");&nbsp;&nbsp;&nbsp;&nbsp;
// 创建图片&nbsp;&nbsp;&nbsp;&nbsp;
$im = imagecreatetruecolor(120, 30);&nbsp;&nbsp;&nbsp;&nbsp;

// 创建颜色&nbsp;&nbsp;&nbsp;&nbsp;
$fontcolor = imagecolorallocate($im, 255, 255, 255);&nbsp;&nbsp;&nbsp;&nbsp;
$bg = imagecolorallocate($im, 0, 0, 0);&nbsp;&nbsp;&nbsp;&nbsp;

// 设置文字&nbsp;&nbsp;&nbsp;&nbsp;
for($i=0;$i<4;$i++) $text .= $ChineseChar[(array_rand($ChineseChar))];&nbsp;&nbsp;&nbsp;&nbsp;

$_SESSION['code'] = $text;&nbsp;&nbsp;&nbsp;&nbsp;
// 设置字体&nbsp;&nbsp;&nbsp;&nbsp;
$font = 'simkai.ttf';&nbsp;&nbsp;&nbsp;&nbsp;

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

// 输出图片&nbsp;&nbsp;&nbsp;&nbsp;
imagepng($im);&nbsp;&nbsp;&nbsp;&nbsp;
imagedestroy($im);&nbsp;&nbsp;&nbsp;&nbsp;
?><br/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" name="check" value="提交验证码">&nbsp;&nbsp;&nbsp;&nbsp;
</form>&nbsp;&nbsp;&nbsp;&nbsp;
</body>&nbsp;&nbsp;&nbsp;&nbsp;
</html>&nbsp;&nbsp;&nbsp;&nbsp;

<?php&nbsp;&nbsp;&nbsp;&nbsp;
/*&nbsp;&nbsp;&nbsp;&nbsp;
* 文件:code.php&nbsp;&nbsp;&nbsp;&nbsp;
* 作用:验证码生成&nbsp;&nbsp;&nbsp;&nbsp;
* 作者:PHP实战群:33918040 - 鱼尾唯一&nbsp;&nbsp;&nbsp;&nbsp;
* 网址:http://bbs.ailf.cn/ http://www.fishwei.com/&nbsp;&nbsp;&nbsp;&nbsp;
* 特注:由 没牙的草 指导 版权所有转载注明出处!有付出才会有收获!&nbsp;&nbsp;
*/&nbsp;&nbsp;&nbsp;&nbsp;
include_once("chinesechar.php");&nbsp;&nbsp;&nbsp;&nbsp;
session_start();&nbsp;&nbsp;&nbsp;&nbsp;
// 设置 content-type&nbsp;&nbsp;&nbsp;&nbsp;
header("Content-type: image/png");&nbsp;&nbsp;&nbsp;&nbsp;
// 创建图片&nbsp;&nbsp;&nbsp;&nbsp;
$im = imagecreatetruecolor(120, 30);&nbsp;&nbsp;&nbsp;&nbsp;

// 创建颜色&nbsp;&nbsp;&nbsp;&nbsp;
$fontcolor = imagecolorallocate($im, 255, 255, 255);&nbsp;&nbsp;&nbsp;&nbsp;
$bg = imagecolorallocate($im, 0, 0, 0);&nbsp;&nbsp;&nbsp;&nbsp;

// 设置文字&nbsp;&nbsp;&nbsp;&nbsp;
for($i=0;$i<4;$i++) $text .= $ChineseChar[(array_rand($ChineseChar))];&nbsp;&nbsp;&nbsp;&nbsp;

$_SESSION['code'] = $text;&nbsp;&nbsp;&nbsp;&nbsp;
// 设置字体&nbsp;&nbsp;&nbsp;&nbsp;
$font = 'simkai.ttf';&nbsp;&nbsp;&nbsp;&nbsp;

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

// 输出图片&nbsp;&nbsp;&nbsp;&nbsp;
imagepng($im);&nbsp;&nbsp;&nbsp;&nbsp;
imagedestroy($im);&nbsp;&nbsp;&nbsp;&nbsp;
?>
</textarea><br/>Tags - <a href="https://blog.liuts.com/tags/php/" rel="tag">php</a> , <a href="https://blog.liuts.com/tags/%25E9%25AA%258C%25E8%25AF%2581%25E7%25A0%2581/" rel="tag">验证码</a>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post//#blogcomment</link>
<title><![CDATA[[评论] PHP汉字验证码的实现]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>