Allow one session only at a time

后端 未结 6 1315
予麋鹿
予麋鹿 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:40

    I'll suggest you to do something like this:

    Suppose when user "A" loges in to the "Com_1", for the first time. Save a unique code in the database against that session, and same with the user session.

    At the mean time if he (user "A") loges in again on "com_2", then check his status in the database and update the unique code in the database.

    again back if same user (user "A") refreshes the page on "com_1", we all you need to do is check the unique code from the session and match it to the database, It is for sure it will not match, then log it out and destroy the session.

    For keeping the user loggedin, even if browser is closed, you can store the cookie on the browser, and re-generate the session accoordingly.

    Hope this helps. Thank you.

提交回复
热议问题