在当前的登录方式中:
$sth = $this->db->prepare("SELECT id, username, active FROM user WHERE username = ? AND password = ?");
$sth->setFetchMode(PDO::FETCH_OBJ);
$sth->execute(array($username, $password));
if (($obj = $sth->fetch()) !== FALSE)
return $obj;
在 login.php 文件上。
$auth = new Auth($db);
$user = $auth->login('username', 'password');
if ($user) {
if ($user->active == 0) { die('You must activate your account')}
//If all is okay... Set the session variables...
}
但是有人告诉我,我宁愿在 login() 方法中设置会话变量,但如果我这样做了,我应该如何处理检查,例如用户是否被激活?