Allow one session only at a time

后端 未结 6 1326
予麋鹿
予麋鹿 2020-11-28 13:23

I would like to make my website to allow only one session at a time. For example, let say user has login to my website on firefox, if the user login again to another browser

6条回答
  •  半阙折子戏
    2020-11-28 13:42

    You can use the following algorithm

    1. create an integer field in the databse userLoggedInCount
    2. On each login increment that flag and store the result in the session.
    3. On each request check the value in the database and the one in the session, and if the one in the session is less than the one in the DB, invalidate() the session and decrement the value in the database
    4. whenever a session is destroyed decrement the value as well

    Credits to Bozho because he posted this, answering to a question here

提交回复
热议问题