PDA

View Full Version : User System Problemo...



lolwut
06-12-2007, 08:12 PM
Righty ho,
Well I have this usersystem, and when they login it sets the correct row in the database so that "logged_in" is equal to 1.
But it only changes to 0 when they press Logout.
Is there any way to make it set to 0 when they're inactive for 1/2 hour?
'cause I can't figure it out.

I tryed to log the time of their last action and compare it with the current time, but that failed because when they closed the tab or window it wasn't able to refresh to time them out, hence a failure there.

Any help appreciated and +repped.

MrCraig
06-12-2007, 08:19 PM
Use a timestamp :)

Add a lastaction field to the database, then add into your functions file



$now = time();
mysql_query("update *USER DATABASE* set lastaction = '$now' where username = 'USERNAME VAR'");
/* Un-Logs inactive people */
$logout = $now - 1300;
mysql_query("update USERDATABASE set logged_in = '0' where lastaction < $logout");
/* End */


Just did quickly so might have errors, so feel free to correct me :)



I tryed to log the time of their last action and compare it with the current time, but that failed because when they closed the tab or window it wasn't able to refresh to time them out, hence a failure there.


Ive made it so that everytime the functions file is loaded (no matter what account is logged in) it will correct all the login things before proceeding.

Want to hide these adverts? Register an account for free!