2 回答
TA贡献1785条经验 获得超4个赞
您需要从数据库获取数据并将其存储在变量中,以便可以在任何需要的地方使用它们。
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);
while($data = mysqli_fetch_array($results)) {
$name = $data['name_from_db']; //Here you put a name of column where you store name in DB
$email = $data['email_from_db']; //Here you put a name of column where you store email in DB
// You can put in session if you want to have it globaly
}
if (mysqli_num_rows($results) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
$_SESSION['name'] = $name ; //This is example where I put in SESSION variable
$_SESSION['email'] = $email; //This is example where I put in SESSION variable
header('location: indexclient.php');
} else {
array_push($errors, "Wrong username/password combination");
}
请注意,在此代码中,您没有为安全做任何事情,它很容易受到攻击。请阅读有关参数化查询和防止SQL注入的保护,以及有关密码哈希的信息。用纯文本发送密码是不安全的!
TA贡献1906条经验 获得超10个赞
在此部分:
if (mysqli_num_rows($results) == 1) {
$_SESSION['username'] = $username;
//Add another entry in SESSION here
$_SESSION['success'] = "You are now logged in";
header('location: indexclient.php');
}
您可以添加一个新条目,例如 $_SESSION['email'] = $result[index_of_email_in_results]
- 2 回答
- 0 关注
- 267 浏览
添加回答
举报