hazz995 Posted January 30, 2010 Share Posted January 30, 2010 I want to display a field that says if a user is logged on or not, also depending on how long the user is inactive for then they will be identified as "logged out" (if the user comes back they are still logged in with the saved session though) Basically if the user has been inactive for 15 Min's then they are identified to other people as 'not online'. I'm not quite sure where to start with this so I just need a little nudge to get me started. Just the way to do it would be good enough, try to limit the amount of code because I want to try doing it myself, not saying I wouldn't mind some code to start me off though Quote Link to comment https://forums.phpfreaks.com/topic/190356-logged-in-or-not/ Share on other sites More sharing options...
premiso Posted January 30, 2010 Share Posted January 30, 2010 Add a database field to the users table called, "Last Activity" if this value is less than 15 minutes show them as being online / logged in. If not show them as being logged out. Quote Link to comment https://forums.phpfreaks.com/topic/190356-logged-in-or-not/#findComment-1004233 Share on other sites More sharing options...
hazz995 Posted January 30, 2010 Author Share Posted January 30, 2010 Add a database field to the users table called, "Last Activity" if this value is less than 15 minutes show them as being online / logged in. If not show them as being logged out. I have a Last Login field which is a TIMESTAMP, so I'll just have to copy that field to Last Activity. I'll have to do some lookup on comparing time since I have no idea how. Quote Link to comment https://forums.phpfreaks.com/topic/190356-logged-in-or-not/#findComment-1004236 Share on other sites More sharing options...
hazz995 Posted January 30, 2010 Author Share Posted January 30, 2010 Alright I'm stuck on this one :/ My poor attempt at trying to +15 mins onto the users last active time, basically how I'm trying to get it to work: if users last active time + 15 mins is higher than current time then they are logged on, else logged off. I tried a few other methods but nothing worked, the lastactive time is in the same format as $date also. (Y-m-d h/i/s) $date = date("Y-m-d h/i/s"); if ($user['lastactive']+15 <=$date) Quote Link to comment https://forums.phpfreaks.com/topic/190356-logged-in-or-not/#findComment-1004261 Share on other sites More sharing options...
dpacmittal Posted January 30, 2010 Share Posted January 30, 2010 Store the last active as timestamp. Then: $active = time() - (15*60); if($lastactive>=$active) echo "logged in"; else echo "logged out"; Quote Link to comment https://forums.phpfreaks.com/topic/190356-logged-in-or-not/#findComment-1004308 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.