suraj Posted May 25, 2022 Share Posted May 25, 2022 i want to create a login script that user can login one device at one time if user login from new device the old login device will logout automatcally using php Quote Link to comment https://forums.phpfreaks.com/topic/314835-login-user-only-one-device-at-a-time/ Share on other sites More sharing options...
ginerjm Posted May 25, 2022 Share Posted May 25, 2022 Suggestion. When a user logs in successfully post a record of it in a separate table, say 'active_users'. Then when they try and login again, check if they are already active (in that table), and if so, delete them and continue on to the normal login process. Your 'active_users' table may need a datetime value in it that allows for a record to expire and be automatically cleaned up by a separate process, perhaps a cron job that runs once a day or something. Quote Link to comment https://forums.phpfreaks.com/topic/314835-login-user-only-one-device-at-a-time/#findComment-1596632 Share on other sites More sharing options...
requinix Posted May 25, 2022 Share Posted May 25, 2022 Use regular sessions, so a session on each device, then associate the session ID with the user record. If it doesn't match on a page load then log the user out. Quote Link to comment https://forums.phpfreaks.com/topic/314835-login-user-only-one-device-at-a-time/#findComment-1596634 Share on other sites More sharing options...
ginerjm Posted May 25, 2022 Share Posted May 25, 2022 Very clever. Didnt' think that far along. @Suraj - scratch my idea! Quote Link to comment https://forums.phpfreaks.com/topic/314835-login-user-only-one-device-at-a-time/#findComment-1596635 Share on other sites More sharing options...
schwim Posted May 27, 2022 Share Posted May 27, 2022 If you want a more persistent login than solely relying on PHP sessions, save a random token to the db and store it in a cookie. If the user shows up in a different PHP session, check the token against the latest active stored in the db. If they differ, scrap all logins for that user and point them towards the login. Quote Link to comment https://forums.phpfreaks.com/topic/314835-login-user-only-one-device-at-a-time/#findComment-1596714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.