如果用户名不存在将用户重定向到页面
问题描述:
我正在为我的爱好网站构建一个密码重置表单,表单本身工作得很漂亮。我使用Dreamweaver CS5。这是我的问题的相关代码。如果用户名不存在将用户重定向到页面
如果密码重置失败,出于任何原因,我想将用户重定向到特定页面。我不确定在Dreamweaver生成它的方式中声明在哪里或如何做到这一点。
这不是所有的代码和问题与安全无关。谢谢。
$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);
?>
答
如果注入失败在希望用户重定向的标头中传递位置。像这样:
if($result1) {
// will return true if succefull else it will return false
// code here
}
else {
header('Location: reenter_pw.php');
}
希望这有助于!
编辑
所以我觉得你的代码应该看起来像this--
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
}
}
我希望你不要在现场环境中使用此打算;这完全不安全。 –
你想知道如何使用SQL重定向到另一个页面? –
如果更新查询不成功并失败,我想将用户重定向到特定页面。 – Cyndi