【问题标题】:Fatal error: Call to undefined method User::password_verify()致命错误:调用未定义的方法 User::password_verify()
【发布时间】:2017-03-08 19:36:47
【问题描述】:

我正在使用教程为博客创建管理员登录。当我单击按钮登录时出现此错误:

致命错误:在第 50 行调用 D:\XAMPP\htdocs\ICT PRoject\class.user.php 中未定义的方法 User::password_verify()

我查看了另一个已回答的问题,该问题说 password_verify() 函数仅从 php 5.0 开始包含。但是,我检查了一下,我的版本是 php 5.6.8。我没有任何其他想法,因此非常感谢您的帮助! 这是错误来自的函数的代码:

public function login($username,$password){ 

    $hashed = $this->get_user_hash($username);

    if($this->password_verify($password,$hashed) == 1){

        $_SESSION['loggedin'] = true;
        return true;
    }       
}

【问题讨论】:

  • 把这个if($this->password_verify($password,$hashed) == 1){ 改成if(password_verify($password,$hashed)){
  • 并确保您了解$this 的含义。
  • 谁对这个问题和所有答案投了反对票而没有任何解释?

标签: php login fatal-error


【解决方案1】:
public function login($username,$password){ 

    $hashed = $this->get_user_hash($username);

    if(password_verify($password,$hashed) == 1){

        $_SESSION['loggedin'] = true;
        return true;
    }       
}

密码验证是 PHP 功能尝试使用它没有 $this。 只需调用该函数并检查布尔值。

【讨论】:

    【解决方案2】:

    Password_verify() 是一个内置函数,但您试图将其作为当前对象的方法调用。并且该函数返回一个布尔值,而不是 1。试试:

    if(password_verify($password,$hashed)){
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-28
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 2012-01-06
      相关资源
      最近更新 更多