此代码位于我的user.php
文件
include('password.php');
class User extends Password{
private $_db;
function __construct($db){
parent::__construct();
$this->_db = $db;
}
private function get_user_hash($email){
try {
$stmt = $this->_db->prepare('SELECT password FROM users WHERE email = :email AND active="Yes" ');
$stmt->execute(array('email' => $email));
$row = $stmt->fetch();
return $row['password'];
} catch(PDOException $e) {
echo '<p class="bg-danger">'.$e->getMessage().'</p>';
}
}
public function login($email,$password){
$hashed = $this->get_user_hash($email);
if($this->password_verify($password,$hashed) == 1){
$_SESSION['loggedin'] = true;
return true;
}
}
public function logout(){
session_destroy();
}
public function is_logged_in(){
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true){
return true;
}
}
}
此代码是我的login.php
文件
function login($email,$password){
$hashed = $this->get_user_hash($email); <--the error is in this line
if($this->password_verify($password,$hashed) == 1){
$_SESSION['loggedin'] = true;
return true;
}
老实说,我不知道该怎么做,我还在学习这些东西。我不太喜欢课程和对象,这就是为什么我要求大家帮我解决这个问题。
答案 0 :(得分:1)
替换此行
$hashed = $this->get_user_hash($email); <--the error is in this line
使用
$user = new User($db);
$hashed = $user->get_user_hash($email);
你不能在课外使用它。您可以在以下SO帖子中了解有关$ this的更多信息。 What does the variable $this mean in PHP?