需要计算的PHP验证码帮助解决
这个验证码无论我输入什么都是验证码错误的,请问各位如何解决啊???这里贴出详细的代码
login.php
<form autocomplete="off" ACTION="login2.php" id="form1" name="form1" method="POST">
<p align="center"> </p>
<table width="200" border="1" align="center" bordercolor="#2C4A70">
<tr>
<td><table width="335" height="69" border="1" align="center" cellpadding="0" cellspacing="0"
bordercolorlight="#000000" bordercolordark="#ffffff" bgcolor="#99CC00">
<tr>
<td height="31" bgcolor="#000000"><span class="STYLE2">验证码:</span></td>
<td width="149" bgcolor="#000000"><label>
<input type="text" name="validate" value="" size=4>
</label></td><img src="mark.php?Action=Login&imgW=80&imgH=30" align="absmiddle"></td>
</tr>
</table></td>
</tr>
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="登陆" />
<input type="reset" name="Submit2" value="重置" />
</div></td>
</tr>
</table>
<p> </p>
</form>
mark.php
<?php
session_start();
/**
* 随机的数字,之和验证码
* 作者 psdshow(at)yahoo.com.cn
* 修改日期 2006-12-20
*/
function getCode ($length = 32, $mode = 0)
{
switch ($mode)
{
case '1':
$str = '123456789';
break;
case '2':
$str = 'abcdefghijklmnopqrstuvwxyz';
break;
case '3':
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case '4':
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
break;
case '5':
$str = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
break;
case '6':
$str = 'abcdefghijklmnopqrstuvwxyz1234567890';
break;
default:
$str = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
break;
}
$result = '';
$l = strlen($str)-1;
for($i = 0;$i < $length;$i ++)
{
$num = rand(0, $l);
$result .= $str[$num];
}
return $result;
}
//建立验证图片
function createAuthNumImg($randStr,$imgW=100,$imgH=40,$fontName)
{
header ("content-type: image/png");
$image = imagecreate($imgW , $imgH);
$color_white = imagecolorallocate($image , 255 , 255 , 255);
$color_gray = imagecolorallocate($image , 228 , 228 , 228);
$color_black = imagecolorallocate($image , 255 , 102 , 204);
for ($i = 0 ; $i < 1000 ; $i++)
{
imagesetpixel($image , mt_rand(0 , $imgW) , mt_rand(0 , $imgH) , $color_gray);
}
imagerectangle($image , 0 , 0 , $imgW - 1 , $imgH - 1 , $color_gray);
for ($i=10;$i<$imgH;$i+=10)
imageline($image, 0, $i, $imgW, $i, $color_gray);
imagettftext($image,16,5,3,25,$color_black,$fontName,$randStr);
for ($i=10;$i<$imgW;$i+=10)
imageline($image, $i, 0, $i, $imgH, $color_gray);
imagepng($image);
imagedestroy($image);
}
$a=GetCode(1,1);
$b=GetCode(1,1);
$c=GetCode(1,1);
$Passport=$a."+".$b."+".$c;
$Total=$a+$b+$c;
$Total;
$_SESSION[$_GET['Action']]=md5(strtoupper($Total));
createAuthNumImg($Passport,$_GET['imgW'],$_GET['imgH'],"verdana.ttf");
?>
后台验证LOGIN2.PHP
<?php
if (!isset($_SESSION)) {
session_start();
}
if($_POST['validate']=$_SESSION['Login']){
//判断session值与用户输入的验证码是否一致;
echo "<script>alert('验证码错误!');history.back();</script>";
}else{
die("请认真填写用户名!");
}
?>