使用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(class)
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");
}
}
答案 0 :(得分: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 and jQuery mobile 1.1.1