PHP /SESSION: Login one per user?

前端 未结 8 1676
臣服心动
臣服心动 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.

提交回复
热议问题