Search code examples
javascriptphpmysqlauthenticationcodeigniter-4

prevent multiple login Codeigniter 4


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


Solution

  • 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.