【发布时间】:2015-06-25 21:36:46
【问题描述】:
此代码在我的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;
}
老实说,我不知道该怎么做,我还在学习这些东西,而且我对类和对象并不是很擅长,这就是为什么我要求大家帮助我解决这个问题。
【问题讨论】:
-
您遇到了什么问题?
-
@MTahir 我已经解决了我之前提出的问题。但我现在的问题是“在 null 上调用成员函数 prepare()”。你能帮我解决这个问题吗?