i want to make login system, and check if user is multiple login and give notification " account already login in other device" in current user login. how to make system like that? I've searched for it on google but couldn't find the right one
check if user is multiple login and give notification " account already login in other device" in current user login
CodePudding user response:
Problem:
You can't really tell when the user is still logged in because the stateless server. Lets say I log in inside an incognito window. When I close the session cookie is deleted. But on the server it's still exists. How do you tell I'm actually logged in or not?
Solution:
You can make a heartbeat request to the server and log the activity. So you have a JS code sending request in every minute so you know the user is online. Also in every request you set the cookie as well.
So you log the last activity time in every minute and every request. When the user tries to log in you check if the logged activity is older than two minutes.
CodePudding user response:
Thanks For your solution How if i add some field in users table? Let say the field name is ses_id If the user login will update ses_id And in js code will send request every 1 minutes for check the ses_id if still match on database and session ses_id
