所以我有一个名为index.php的登录页面,该页面似乎没有重定向到home.php页面。 我尝试使用所有正确的用户详细信息登录,但它仍然保留在index.php页面上,它还清除字段中的数据
我查看了我的代码,似乎无法找到问题
<?php
require_once'Dbconfig.php';
function login($umail, $upass)
{
$stmt = $dbh->prepare("SELECT * FROM users WHERE
emailAddress=:umail AND userPass=:upass");
$stmt->execute(array(':umail'=>$umail, ':upass'=>$upass));
$userRow=$stmt->fetch(PDO::FECTH_ASSOC);
if($stmt->rowCount() ==1)
{
$hashed = $this->get_user_hash($upass);
if($this->password_verify($upass, $hashed) == 1)
{
$_SESSION['user_session'] =
$userRow['emailAddress'];
return true;
}
else
{
return false;
}
}
}
if(isset($_POST['btn_login']))
{
$umail = $_POST['txt_umail'];
$upass = $_POST['txt_upass'];
if($user->login($umail, $upass))
{
header('Location: home.php');
exit;
}
else
{
$error[] = 'Wrong email or password!';
}
}
?>
答案 0 :(得分:0)
您可以尝试使用其他条件
<?php
require_once'Dbconfig.php';
function login($umail, $upass){
$stmt = $dbh->prepare("SELECT * FROM users WHERE emailAddress=:umail");
$stmt->bindValue(":umail", $umail);
$stmt->execute();
$userRow = $stmt->fetchAll();
if($stmt->num_rows ==1){
$hashed = $this->get_user_hash($upass);
if($this->password_verify($upass, $hashed)){
$_SESSION['user_session'] = $userRow['emailAddress'];
return true;
}else{
return false;
}
}
}
?>