php注册页面验证码,不知道哪儿有错误,每次提交就算验证码打错了,居然也能成功提交。
以下是注册页面的全部代码,每次提交验证码不管是输入正确还是错误,内容都会被成功提交。求解决大家看看代码哪儿有错误。
<?php require_once('Connections/conn.php'); ?>
<?php session_start();?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO user_zc (username, pass, phonenumber, realname, sex) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['pass'], "text"),
GetSQLValueString($_POST['phonenumber'], "int"),
GetSQLValueString($_POST['realname'], "text"),
GetSQLValueString($_POST['select'], "text"));
if ($_POST['yzm'] !== $_SESSION["vocode"]) {
header("location: ". "user_zcsb.php" );
}
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "user_zccg.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户注册</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
<table width="240" border="0">
<tr>
<td height="54" colspan="2">会员账号注册</td>
</tr>
<tr>
<td width="44" height="90">*用户名</td>
<td width="186"><input name="username" type="text" id="username" maxlength="12" /></td>
</tr>
<tr>
<td height="87">*密码</td>
<td><label>
<input name="pass" type="password" id="pass" />
</label></td>
</tr>
<tr>
<td height="39">*性别</td>
<td><label>
<select name="select" id="select">
<option value="男">男</option>
<option value="女">女</option>
</select>
</label></td>
</tr>
<tr>
<td height="75">*手机</td>
<td><label>
<input name="phonenumber" type="text" id="phonenumber" />
</label></td>
</tr>
<tr>
<td height="96">*真实姓名</td>
<td><label>
<input name="realname" type="text" id="realname" />
</label></td>
</tr>
<tr>
<td height="68" colspan="2"><label>*验证码
<input name='yzm' type='text' id="yzm" size='5' />
<img src='vcode/vcode.php' alt="" border='0' align='absmiddle' /><br />
</label></td>
</tr>
<tr>
<td height="130" colspan="2"><input type="submit" name="Submit" value="提交" />
<input type="reset" name="Submit2" value="重置" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
[解决办法]
首先呢,确认程序是否走到了包含验证功能的代码中
$_POST['yzm'] !== $_SESSION["vocode"]
输出上述两个值。在程序的上下几行都输出几个字符判断下程序的走向,这个不难的
[解决办法]
兄弟!仔细检查一下你的'vcode/vcode.php' 这个文件里$_SESSION["vocode"]这个值是否记住了,还有就是看看是否仅过了你那个验证码判读的步骤哦