PHP /SESSION: Login one per user?

前端 未结 8 1673
臣服心动
臣服心动 2020-12-08 23:20

How can i do so only 1 can be online for the 1 user at the time? Idea ?

So you e.g can not login to User1 on one pc/browser and then on the other pc/browser login to

相关标签:
8条回答
  • 2020-12-09 00:22

    My Idea Would be continue from here the first answer I have seen :

    You could store the session ID (and last access time) in a database, and reject login attempts for users with different session IDs if the last-access time is too recent(say, within the past 20 minutes). Clear the ID on logout, of course.

    Create a column current _session in database , when users loggeed in save the current session in table here we assume that we have a login time is set for 20 minutes and user after login closes his browser and again came back in next 10 minutes ,so here we have his old session set which is valid for 20 minutes , but in actual last time he closed the browser so this time he will have a new session id , so we will catch this session mismatch and here will ask user to login again by deleting the old record we have kept.

    0 讨论(0)
  • 2020-12-09 00:25

    The best way to do this is to create an extra column in your users table which is set at 0(false) by default and when logged in set to 1 (true). Then when the user logs out reset to 0. Run a check every couple hours which requires a user to click yes to continue with the session or be auto logged out after a count down timer reaches zero. The floor here is that the longer you leave it until you run your check the longer a user would have to wait to be able to login again if they left your site and came straight back without logging out properly as the user table would still be true until logged out. The side effect is asking for user input more often against losing access for a greater length of time. It needs to be weighed up so that it's not annoying for the user. You could detect that the user has left your site using js and then log out but the user can switch this off and therefore is unreliable.

    0 讨论(0)
提交回复
热议问题