从数据库转到会话 [英] Going from database to sessions

查看:43
本文介绍了从数据库转到会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我的注册非常顺利,因为必填字段包含您的电子邮件,姓名和密码.登录时要求您提供电子邮件和密码.

Well I have my register done all nice, as required fields it holds your email, name, and password. When you log in it asks for your email and password.

当他们登录时,我将其保存为会话中的电子邮件,但是即使他们没有键入,我如何将其名字存储在会话中?谢谢.

When they log in I have it so that they have their email stored in a session, but how do I get their firstname stored in a session, even though they didn't type it? Thanks.

问题是,我不知道用户的名字,所以...

The thing is, I don't know the users first name so...

推荐答案

当他们登录并检查登录凭据(电子邮件和密码)时,如果找到用户,请同时选择其名字并将其存储在另一个会话变量:

When they log in and you are checking the login credentials (email and password), if you find the user, select their first name as well and store it in another session variable:

$query = 'SELECT firstname FROM users WHERE email = $email AND password = $password LIMIT 1';
...
if ($result && mysql_num_rows($result) == 1) {
    $row = mysql_fetch_object($result);
    $_SESSION['firstname'] = $row->firstname;
    ...

基于表名和列名可能并不完全正确,但这是一般性的想法.

That might not be exact based on table and column names, but that's the general idea.

这篇关于从数据库转到会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆