我正在基于mysql表进行php登录。它在Chrome中运行良好,但在Firefox和Edge中,当我输入用户名和密码时,我只是回到了登录页面。 (使用正确或不正确的凭证)
这是我的PHP代码..
<?php session_start();
if(isset($_POST['login'])) {
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$sel_user = $con->prepare("SELECT id, username, pass, gid FROM employees WHERE gid!=4 AND username=?");
$sel_user->execute([$uname]);
$check_user = $sel_user->fetch();
if(count($check_user)>0 && password_verify($pass, $check_user['pass'])) {
$_SESSION['username']=$check_user['username'];
header("Location: xadmin.php" );
exit;
}
else {
echo "<script>alert('Email or password is not correct')</script>";
}};?>
这是html表单..
<form action="login.php" method="post">
<table width="100%" border="0">
<tbody>
<tr>
<td bgcolor="#3B3B3B" height ="35" class="BodyTxtB" align="center">Administrator Login</td></tr>
<tr height="20"><td></td></tr>
<tr>
<td class="BodyTxtB" align="center">Username</td>
</tr>
<tr>
<td class="BodyTxtB" align="center"><input type="text" class="BodyTxtBC" name="uname" required="required"/></td>
</tr>
<tr height="20"><td></td></tr>
<tr>
<td class="BodyTxtB" align="center">Password</td>
</tr>
<tr>
<td class="BodyTxtB" align="center"><input type="password" class="BodyTxtBC" name="pass" required="required"/></td>
</tr>
<tr height="20"><td></td></tr>
<tr height="35"><td align="center"><input type="image" src="images/btn_login.jpg" name="login" value="Login"/></td></tr>
<tr height="20"><td></td></tr>
</tbody>
</table>
</form>
以下是来自xadmin.php的验证
<?php session_start();
if (!isset($_SESSION['username']))
{
header("Location: login.php?e=access_denied");
exit();
}
?>
有谁知道导致这个问题的原因是什么?
更新:虽然与原始问题无关或提供了答案,但我已更新此帖以修复mysql注入和密码加密问题
答案 0 :(得分:3)
Firefox / Edge不会通过name
的{{1}}
如果您执行<input type="image" ... />
并使用Firefox提交表单,则会获得:
print_r($_POST)
然而,对Chrome做同样的事情:
Array
(
[login_x] => 0
[login_y] => 0
)
......你有它。
您可以将登录作为隐藏表单字段传递:
Array
(
[login_x] => 8
[login_y] => 8
[login] => Login
)