如何防止PHP/MySQL网站中的并发用户登录? [英] How to Prevent Concurrent User Logins in PHP/MySQL Site?

查看:163
本文介绍了如何防止PHP/MySQL网站中的并发用户登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发将主持网络广播的网站的用户管理部分.目标是防止并发使用相同的用户名(电子邮件地址).也就是说,我们不希望两个人使用一个登录名来查看事件.

I am developing the user management portion of a website that will host a webcast. The goal is to prrevent the same user nam (email address) from being used concurrently. That is, we don't want two individuals using one login to view the event.

我已经建立了一个表,其中包含以regID作为主键的用户注册数据.我的想法是创建一个以用户名为主键,在注册表中为用户名的外键的登录历史记录表.登录历史记录表仅会在用户登录站点时添加时间戳.但是,这无法实现我的目标,即防止多个人使用相同的登录名.

I've already setup a table that holds the user registration data with regID as primary key. My thought is to create a login history table with username as primary key, foreign key to user name in registration table. The login history table would simply timestamp when the user logs into the site. However, this won't accomplsih my goal of preventing more than one individual from using the same login name.

相反,将登录历史记录或用户表中的登录状态字段设置为1(用于登录)和0(用于注销)会更好吗?它需要一个存储过程来在登录和注销时更新值,并且需要在用户登录时进行验证,如果登录状态= 1,则用户已经登录并且无法再次登录.这是可行的方法吗?

Instead, would it be better to have a login status field either in the login history or user table that is set to 1 for logged in and 0 for logged out? It would need a stored procedure to update the value at login and at logout, and would need to be validated when a user logs in such that if login status = 1, user already logged in and cannot login a second time. Is this a feasible approach?

请分享您用来防止同一登录凭据在多个人之间共享的其他方法.

Please share other methods you've used to prevent the same login credential from being shared amongst multiple individuals.

谢谢, 席德

推荐答案

如果其他人可以使用相同的凭据登录,则可以注销已经登录的用户,则可以执行以下操作:当用户登录时,generate数据库中该用户的随机ID,并在 cookie 会话中使用相同的ID.两者必须匹配才能进行身份验证.

If it is OK to logout an already logged in user if someone else logs in with the same credentials then you could do the following: when a user logs in generate a random ID in your database for that user and the same in a cookie session. The two must match to authenticate.

这篇关于如何防止PHP/MySQL网站中的并发用户登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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