2017-02-18 85 views
-1

我正在为我的爱好网站构建一个密码重置表单,表单本身工作得很漂亮。我使用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); 

?> 
+2

我希望你不要在现场环境中使用此打算;这完全不安全。 –

+2

你想知道如何使用SQL重定向到另一个页面? –

+0

如果更新查询不成功并失败,我想将用户重定向到特定页面。 – Cyndi

回答

1

如果注入失败在希望用户重定向的标头中传递位置。像这样:

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 
    } 
} 
+0

这实际上有很大帮助。我会删除行“标题(sprintf(”位置:%s“,$ updateGoTo));”并将其替换为“header('Location:reenter_pw.php');”并添加else语句? – Cyndi

+0

我编辑了我的答案我认为这是你想要的。如果用户名存在,您希望重定向到'login.php',如果不存在,则重定向到其他页面。 – neophyte

+0

该功能无效,在为页面添加主要URL时,它只是自动将我重定向到我设置为reenter_pw.php的页面,而无需加载父页面。 – Cyndi

相关问题