所以我把一個非常粗略的登錄表單使用PHP和MySQL數據庫,我有它設置(或因此我認爲),以回重定向到登錄頁面與「loginFailed =真&原因=密碼」」我。我試圖讓它重定向回登錄,並顯示一個不正確的密碼信息,但它只是重定向到主索引頁不正確的密碼重定向到不正確的頁面?
我在這裏做錯了什麼?當然, 。現有的代碼,由於我缺乏的編碼知識,但它並重定向之前工作打算了一下
下面是代碼:
passwordcheck .PHP
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$password = stripslashes($password);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("password");
header("location:admin.html");
}
else {
die(header("location:login.html?loginFailed=true&reason=password"));
}
?>
這裏是在登錄頁面的密碼字段:
<span class="add-on"><i class="icon-list-alt"></i></span>
<input type="password" id="inputIcon" class="span4" name='password' id='password' maxlength="50" placeholder="<?php $reasons = array("password" => "Yo shitbird, wrong password."); if ($_GET["loginFailed"]) echo $reasons[$_GET["reason"]]; ?>" />
</div>
所以沒有用戶名場,只是一個密碼?這意味着每個用戶都需要一個唯一的密碼;如果你爲他們生成密碼,這可能會有效,但最好還是有一個用戶名。 –