登录失败后,我试图重定向到同一页面,但我被重定向到。/login.php这是我的代码:Index.php:<body> <h1><strong>Login</strong></h1> <form action="login.php" method="POST"> <table id="mytable"> <tr> <td><select name="type"> <option value="Admin">Admin</option> <option vale="User">User</option> </select></td> </tr> <tr> <td><input type="text" name="username" placeholder="Username"><br><br> </td> </tr> <tr> <td><input type="password" name="password" placeholder="Password"><br><br> </td> </tr> <tr> <td><input type="submit" value="Login" ><br><br> </td> </tr> </table> </form> </form></body></html>登录.php:?phprequire 'ceva.php'; $type=$_POST['type']; $username=$_POST['username']; $password=$_POST['password'];//if(!empty($username) && !empty($password))//{$sql= "SELECT * FROM login WHERE username ='$username' and password='$password' and type='$type'"; // selecteaza din baza de date login$rezultat= mysqli_query($con, $sql); while($rand=$rezultat->fetch_assoc()) { if($rand['username'] == $username && $rand['password'] == $password && $rand['type'] == 'Admin') //verificare array { header("Location: admin.php"); //muta in pagina admin.php }else if ($rand['username'] == $username && $rand['password'] == $password && $rand['type'] == 'User'){ header("Location: user.php"); }else { header("Location: index.php"); }}如果凭据正确,我将被重定向到user.php或admin.php很好,但如果它们是错误的,我应该被重定向到index.php
1 回答
翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
您的查询只生成与用户名、密码和类型实际匹配的行。因此,只有在凭据正确的情况下才会运行 while 循环。您需要将重定向放在 index.php 之后。
while($rand=$rezultat->fetch_assoc())
{
if($rand['username'] == $username && $rand['password'] == $password && $rand['type'] == 'Admin') //verificare array
{
header("Location: index.php");header("Location: admin.php"); //muta in pagina admin.php
exit;
}else if ($rand['username'] == $username && $rand['password'] == $password && $rand['type'] == 'User'){
header("Location: user.php");
exit;
}
}
header("Location: index.php");
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
0/150
提交
取消