gpt4 book ai didi

php - 代码不回显 "ok"

转载 作者:搜寻专家 更新时间:2023-10-30 23:09:19 27 4
gpt4 key购买 nike

我已经搜索了很长时间,但我再次陷入困境,当我为与数据库中的密码匹配的用户输入正确的密码时,我的代码没有回显“ok”。

其他一切正常,我不确定我是否错过了任何愚蠢的事情;我可能有,所以为我的愚蠢道歉 :)

PHP:

class User {
private $_db, $data;

public function __construct($user = null) {
$this->_db = DB::getInstance();
}

public function create($fields = array()) {
if(!$this->_db->insert('users', $fields)) {
throw new Exception('There was a problem registering');
}
}

public function find($user = null) {
if($user) {
$field = (is_numeric($user)) ? 'id' : 'username';
$data = $this->_db->get('users', array($field, '=', $user));

if($data->count()) {
$this->_data = $data->first();
return true;
}
}
return false;
}

public function login($username = null, $password = null) {
$user = $this->find($username);

if($user) {
if($this->data()->password === Hash::make($password, $this->data()->salt)) {
echo 'ok';
}
}

return false;
}

private function data() {
return $this->_data;
}
}

最佳答案

在你的 login() 上,你必须像这样重写..

 public function login($username = null, $password = null) {

$user = $this->find($username);


if($user) {
if($this->data()->password === Hash::make($password, $this->data()->salt)) {
//echo 'ok';
return true;
}

}
else { return false; }
}

注释掉 echo 并从那里返回 true。所以你将从你的实例中调用你的函数,比如

if($someinst->find('someuser'))
{
echo "User Found";
}
else { echo "Not Found"; }

关于php - 代码不回显 "ok",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22108941/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com