Restrict user session to one per login

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 348
Joined: 2018-03-04 09:30
Location: David

Restrict user session to one per login

Post by D Oliveira » 2019-11-29 23:57

Is there a way to log out a user if this same account has logged in somewhere else?

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 348
Joined: 2018-03-04 09:30
Location: David

Re: Restrict user session to one per login

Post by D Oliveira » 2019-11-30 08:58

got overwhelmed with the research apparently cron jobs dont work that well for that feature, thinking about something like that now:

home.php

Code: Select all

if ( $ip_db1 == '' ){

 		$ip_db1 = $ip_self

 }else{

 		if ( $ip_db2 == ''){
	 	$ip_db2 = $ip_self
	 	}

}

if ( $ip_self == $ip_db1 or $ip_self == $ip_db2){
// success		
}else{
	
	you can only be logged in 2 devices at a time.

	Refresh connection 
	( you will have to wait 5 minutes for access ) // setlock = 1 // when lock = 1 show timer then setlock = '' after 5 min

}

// log out button

if ( $ip_self == $ip_db1 ){
	
	$ip_db1 = ''
	
}

if ( $ip_self == $ip_db2 ){
	
	$ip_db2 = ''
	
}

log out function
I wonder if IP addresses change constantly or if its safe to assume its gonna persist for that purpose

User avatar
a.gneady
Site Admin
Posts: 1287
Joined: 2012-09-27 14:46
Contact:

Re: Restrict user session to one per login

Post by a.gneady » 2019-12-01 18:26

You'd need to log user logins into a new database table, storing the user agent (which is more accurate than the IP address) ... The user agent is stored in $_SERVER['HTTP_USER_AGENT'] ... So, using the login_ok hook in hooks/__global.php, you should check the logins table to see if the current user has a session with the same user agent ... If she does, then she is logging from the same device and it's OK to proceed. If she does have a session, but with a different user agent, it means she's logged in from another device. In that case, you could log her out and display an error explaining that she can log in from only one device.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

Post Reply