2017-02-18 82 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

相關問題