How to Prevent Concurrent User Logins in PHP/MySQL Site?

后端 未结 6 1633
北恋
北恋 2020-12-16 18:58

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.

6条回答
  •  一向
    一向 (楼主)
    2020-12-16 19:47

    Without rolling your own session handler, you could do a little parallel tracking. When a user logs in, you can store the user's session ID and login time in the database (maybe inside the user information table). The login script could then check for the existence if this sessionID and allow/deny login based on the presence of the session ID. If the ID's null/blank, then the user logs in. If there's a session ID present, and it's more than X minutes old, allow the login. Otherwise deny them.

    Of course, you'd probably want to roll your own session cleanup handler at that point, so that when stale session files get deleted, you can remove the associated IDs from the database at the same time.

提交回复
热议问题