回调函数返回false CodeIgniter

时间:2016-10-09 10:22:04

标签: php codeigniter callback

为什么我的代码在我的回调代码的if条件中返回false。我尝试var_dump每个值和

这是var_dump

的输出
var_dump($old_password_hash); = string(32) "25d55ad283aa400af464c76d713c07ad"
var_dump($old_password_db_hash); = object(stdClass)#24 (1) { ["user_password"]=> string(32) "25d55ad283aa400af464c76d713c07ad" }

这两个值在if($old_password_hash != $old_password_db_hash) {

中并不令人满意

这是我的完整代码

public function oldpassword_check($old_password){
    $id = $this->input->post('userid');

    $old_password_hash = md5($old_password);
    $old_password_db_hash = $this->prof_model->fetch_pwrod($id);

    //var_dump($old_password_hash);

    var_dump($old_password_db_hash);

    if($old_password_hash != $old_password_db_hash) {

        $this->form_validation->set_message('oldpassword_check', 'Old password not match');
        return FALSE;

    } else {

        return TRUE;

    } 

}

1 个答案:

答案 0 :(得分:3)

$old_password_hash字符串

$old_password_db_hash对象

他们永远不会平等。 string 从不等于object

这就是为什么$old_password_hash != $old_password_db_hash始终是 true 的原因。因此返回FALSE

正确检查是:

// take `user_password` property of an object
if ($old_password_hash != $old_password_db_hash->user_password) {
  $this->form_validation->set_message('oldpassword_check', 'Old password not match');
  return FALSE;
}
else {
  return TRUE;
}
相关问题