您的位置:首页 > 其它

利用本地图片制作验证码(简短、美观)

2010-07-26 11:46 225 查看
<?php
$str=array("大","更","创","天","科","客","博","技","立","新"); //汉字验证码
$word=strlen($str);
for($i=0;$i<4;$i++){
$num=rand(0,$word*2-1); //$word=$word*2-1
$img=$img."<img src=' images/checkcode/".$num.".gif' width='16' height='16'>"; //显示随机图片
$pic=$pic.$str[$num]; //将图片转换成数组中的文字
}
?>

处理代码:

<script language="javascript">
function check(form){
if(form.txt_yan.value==""){
alert("请输入验证码");form.txt_yan.focus();return false;
}
if(form.txt_yan.value!=form.txt_hyan.value){
alert("对不起,您输入的验证码不正确!");form.txt_yan.focus();return false;
}
}
</script>
<body>
<form name="form" method="post" action="">
<table width="447" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#009A31" bgcolor="#99FF33">
<tr>
<td width="447" height="53" align="center"><span class="style1"> 简单的文字验证码</span>
<hr width="80%">
<span class="style1"> </span> 验证码:
<input type="text" name="txt_yan">
<?php
$num=intval(mt_rand(1000,9999));
echo "<font color=red size=4><strong>".$num."</strong></font>"; //自动生成一组4位的随机数
?>

<input type="hidden" name="txt_hyan" id="txt_hyan" value="<?php echo $num;?>">
<br>
<br>
<input type="submit" name="Submit" value="验证" onClick="return check(form);">
 
<input type="reset" name="Submit2" value="重置"></td>
</tr>
</table>
</form>
<?php
if($_POST[Submit]!=""){
echo "您输入的验证码通过,感谢您的加盟...";
}
?>
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: