Login 不正确的密码重定向到不正确的页面?

Login 不正确的密码重定向到不正确的页面?,login,Login,因此,我使用php和mysql数据库创建了一个非常粗糙的登录表单,并将其设置为(或者我认为是这样)使用“loginFailed=true&reason=password”重定向回登录页面。我试图让它重定向回登录,并显示错误的密码消息,但它只是重定向到主索引页面 我在这里做错了什么?当然,由于我缺乏编码知识,我大量借用了一些预先存在的代码,但在重定向之前,它确实起到了预期的作用 代码如下: passwordcheck.php // Connect to server and select data

因此,我使用php和mysql数据库创建了一个非常粗糙的登录表单,并将其设置为(或者我认为是这样)使用“loginFailed=true&reason=password”重定向回登录页面。我试图让它重定向回登录,并显示错误的密码消息,但它只是重定向到主索引页面

我在这里做错了什么?当然,由于我缺乏编码知识,我大量借用了一些预先存在的代码,但在重定向之前,它确实起到了预期的作用

代码如下:

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>

尝试将命令移出调用:

这段代码还有许多其他潜在的问题,我建议您阅读一些关于这一主题的教程;尽管要小心,有许多低质量的PHP教程可能会教您一些危险的做法。了解更多信息非常重要,特别是如果这段代码要放在可公开访问的web服务器上


其中一个问题是,您正在以纯文本形式存储密码。密码永远不应该以纯文本形式存储,它们应该用盐腌制并存储。这是一个非常有用的工具来帮助解决此问题。

因此没有用户名字段,只有密码?这意味着每个用户都需要一个唯一的密码;如果您正在生成我曾考虑过加密密码,但实际上它只适用于个人网站侧边栏的一小部分可编辑部分。不过……我可能想研究加密,只是为了培养未来项目的技能。
else {
    header("location:login.html?loginFailed=true&reason=password");
    die();
}