我正在基于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注入和密码加密的问题
火狐/边缘不通过name
的<input type="image" ... />
如果您执行print_r($_POST)
并使用Firefox提交表单,则会得到:
Array
(
[login_x] => 0
[login_y] => 0
)
但是,使用Chrome做同样的事情:
Array
(
[login_x] => 8
[login_y] => 8
[login] => Login
)
...就在那里。
您可以通过登录作为隐藏的表单字段进行传递:
<input type="image" src="images/btn_login.jpg" />
<input type="hidden" name="login" value="Login" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句