drpmazn9021 2017-03-28 17:56
浏览 63

从签入的日志中获取数据,如果我按下刷新它将重定向到白页,它将转到它必须指向的页面

I am getting some information from the login page form.

When I press submit, it goes to a check-login.php page where there it checks from the database if the credentials are correct or wrong.
Then it redirects to a track page.

My problem is that when I press submit on the log in page with the correct credentials.
It redirects to a white page.
And then, if I press refresh, it redirects to the correct page.

<div>
  <h1>Login Form</h1>
  <form action="check-login.php">
    <input type="text" name="user" placeholder="user">
    <input type="password" name="password" placeholder="password">
    <input type="submit" value="log in">
  </form>
</div>

This is the check-login php page

<?php
session_start();
$user=$_GET['user'];
$pass=$_GET['password'];
include("dblogin.php");
$sql="SELECT * FROM login";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    if($user==$row["username"] && $pass==$row["password"]){
        $_SESSION["userid"]=$row["id"];
        header ("Location: tracks.php");
  }
}
if ($_SESSION["userid"]==""){
  header ('Location: login.html?message=Wrong Username or Password');
}
?>
  • 写回答

3条回答 默认 最新

  • dqwh1202 2017-03-28 18:17
    关注

    Try the following code to make a redirect:

    http_response_code(302); // send redirect code
    header('Location: /tracks.php'); // send Location header
    exit(0); // don't send anything else
    
    评论

报告相同问题?