我正在学习 PHP 并已经报名参加了一门课程。我的用户登录信息如下。
我的问题是,在登录时,我是否必须选择我想要在会话中使用的所有字段?我能否只选择电子邮件并通过它拉取所有行,还是必须在登录时选择所有行?
例如,以 uid = uid 的形式,不应该提取 id = id 的用户的所有信息吗?
$_SESSION['email'] = $email;
$_SESSION['uid'] = $row['uid'];
function login_user($email, $password)
{
$sql = "SELECT pwd, uid, user, birthdate FROM users WHERE email = '" . escape($email) . "' AND active = 1";
$result = query($sql);
if (row_count($result) == 1) {
$row = fetch_array($result);
$db_password = $row['pwd'];
if (password_verify($password, $db_password)) {
$_SESSION['email'] = $email;
$_SESSION['uid'] = $row['uid'];
$_SESSION['username'] = $row['username'];
$_SESSION['birthdate'] = $row['birthdate'];
return true;
} else {
return false;
}
return true;
} else {
return false;
}
}