0

使用 时header("Location: url.php),在我们的例子中,URL 不会更改为新页面login.php(因此刷新时它只会返回登录页面)。如果页面以表单形式运行,则无需登录。所以我现在的问题是,是否有人知道我们如何使用正确的 URL 访问正确的页面。或者也许有人知道可能导致这种情况的原因。

Login.php(逻辑)

$user = new User();
if(!empty($_POST["btnLogin"])) {
  try {
    $user = new User();
    $user->Username = $_POST["username"];
    $user->Password = $_POST["password"];
    $user->Login();
  }
  catch(Exception $e) {
   $feedback_error = $e->getMessage();
  }
}

login.php(表单)

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <input id="username" type="text" name="username" placeholder="username" />
  <input id="password" type="password" name="password" placeholder="password" />
  <p>Not yet signed up? <a href="register.php" >Register</a></p>
  <input type="submit" name="btnLogin" data-theme="b" value="Sign in">
</form>

user.php(类)

public function Login() {
  $salt = "ab4p73wo5n3ig247xb1w9r";
  $db = new Db();
  $select = "SELECT * FROM users WHERE username = '" .
    $db->mysqli->real_escape_string($this->Username) .
    "' AND password = '" .
    $db->mysqli->real_escape_string(md5($this-> Password . $salt)) . "';";
  $result = $db->mysqli->query($select);
  if($result->num_rows == 1) {
    $_SESSION["loggedin"] = true;
    $_SESSION["username"] = $this->Username;
    //header("Location: show_bugs.php");
  } else {
    throw new Exception("Please enter correct username and password");
  }
}
4

1 回答 1

0

这显然是使用 JQM 时的一个已知错误。显然有一种将 data-ajax 称为错误的解决方法:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" data-ajax="false">

这里的错误 - https://github.com/jquery/jquery-mobile/issues/2836

堆栈溢出问题 - Symfony 2 和 jQuery mobile 1.1.1

于 2013-06-12T14:16:20.677 回答