简体   繁体   English

用户数据库结构,允许多次同时登录同一帐户

[英]Users database structure that allows multiple simultaneous logins to same account

A feature that is currently missing from one of my web apps is that a single user can only be logged in on one machine at a time. 我的一个Web应用程序当前缺少的一项功能是,单个用户一次只能登录到一台计算机上。 That is, if the users logs in elsewhere, his previous session will be logged off. 也就是说,如果用户在其他地方登录,则他的先前会话将被注销。

This is due to my current users table having the columns: 这是由于我当前的用户表具有以下列:

user: id, username, hash, salt... cursession

When each user logs in, the session ID is put into the "cursession" field and on each page-load, is checked against the database. 当每个用户登录时,会话ID都会放入“ cursession”字段中,并在每次页面加载时都对照数据库进行检查。 As a result, only one "session" can be active at a time. 结果,一次只能激活一个“会话”。

  1. Is the current table structure and method secure and standard? 当前的表结构和方法是否安全和标准? This system was pretty much improvised, and I have no professional experience. 该系统几乎是即兴的,我没有专业经验。
  2. What would be a way to allow multiple simultaneous logins? 允许多个同时登录的方法是什么? I'm simply thinking of adding a "sessions" table with more userid-cursession relations, but what's the standard method for doing this? 我只是在考虑添加具有更多用户标识与会话关系的“会话”表,但是执行此操作的标准方法是什么?

I propose that you put the current logged in userid in the user's session (as a session variable), and drop the cursession field from the table altogether. 我建议您将当前登录的用户ID放在用户的会话中(作为会话变量),并从表中完全删除cursession字段。 You don't need to reinvent session handling since PHP already has it built-in. 由于PHP已经内置了会话处理,因此您无需重新发明会话处理。

That way the user can be logged in at multiple computers at once. 这样,用户可以一次在多台计算机上登录。 Session variables are safe too, since they're not manipulated by the browser. 会话变量也很安全,因为它们不会被浏览器操纵。 The only thing kept in the browser is a session id which identifies the current session, all other data is stored on the server-side. 浏览器中唯一保留的是一个会话ID,用于标识当前会话,所有其他数据都存储在服务器端。 The only thing that will happen if the user changes his browser cookies is that he will be logged out (start an empty session), so he can't force himself to log in as someone else. 如果用户更改其浏览器Cookie,唯一会发生的事情是他将被注销(开始一个空会话),因此他不能强迫自己以其他人的身份登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM