<?php
include "config.php";
class Users extends Config {
public function login($username, $password) {
try {
$this->db->beginTransaction();
$stmt = $this->db->prepare("SELECT `username`, `password` FROM `users` WHERE `username` = ? AND `password` = ? LIMIT 1");
$stmt->execute(array($username, $password));
if($stmt->rowCount == 1) {
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
header("Location: index.php?p=loggedin");
exit();
}
} else {
header("Location: index.php?p=false");
exit();
}
$this->db->commit();
} catch(PDOException $ex) {
$this->db->rollBack();
echo $ex->getMessage();
}
}
}
$users = new Users();
?>
Run Code Online (Sandbox Code Playgroud)
如您所见,我的代码有两种header()方法,其中一种方法重定向到登录页面,而另一种方法重定向到错误页面.
我相信据我所知,我的脚本应该根据我的输入重新定向到登录页面,这是正确的,但它的行为方式是出乎意料的.
它会重定向到错误页面而不是登录页面.请看一看,告诉我它不起作用的原因?谢谢!此外,如果您发现我的代码中存在任何缺陷,请随意提出一些批评,因为我希望改善自己.非常感谢.