我正在为我的爱好网站构建一个密码重置表单,表单本身运行得很漂亮。我使用Dreamweaver CS5。这是我的问题的相关代码。
如果密码重置失败,无论出于何种原因,我想将用户重定向到特定页面。我不知道Dreamweaver生成它的方式在语句中何处或如何做到这一点。
这不是所有的代码,而且这个问题与security.Thanks无关。
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1_reset")) {
$password_md5 = md5($_POST['password']);
$updateSQL = sprintf("UPDATE users SET password=%s WHERE username=%s AND email=%s AND security=%s",
GetSQLValueString($password_md5, "text"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['security'], "text"));
mysql_select_db($database_login_form, $login_form);
$Result1 = mysql_query($updateSQL, $login_form) or die(mysql_error());
$updateGoTo = "login.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$totalRows_resetpass = mysql_num_rows($resetpass);mysql_select_db($database_login_form, $login_form);
$query_resetpass = "SELECT * FROM users";
$resetpass = mysql_query($query_resetpass, $login_form) or die(mysql_error());
$row_resetpass = mysql_fetch_assoc($resetpass);
$totalRows_resetpass = mysql_num_rows($resetpass);
?>
答案 0 :(得分:1)
如果注入失败将标题中的位置传递到您希望用户重定向的位置。像这样:
if($result1) {
// will return true if succefull else it will return false
// code here
}
else {
header('Location: reenter_pw.php');
}
希望这有帮助!
修改强>
所以我认为你的代码应该是这样的 -
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1_reset")) {
$password_md5 = md5($_POST['password']);
$updateSQL = sprintf("UPDATE users SET password=%s WHERE username=%s AND email=%s AND security=%s",
GetSQLValueString($password_md5, "text"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['security'], "text"));
mysql_select_db($database_login_form, $login_form);
$Result1 = mysql_query($updateSQL, $login_form) or die(mysql_error());
$updateGoTo = "login.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
if($result1) {
// will return true if succefull else it will return false
header(sprintf("Location: %s", $updateGoTo));
}
else {
header('Location: reenter_pw.php');//The specific page where you want to redirect the user
}
}