Hyaku_ Posted January 8, 2007 Share Posted January 8, 2007 Hi!I'm trying to check, for how long user has been logged in. This is basic idea, but it doesn't quite work right:[code]echo "You have been logged in for " . round((date("ymdHis") - $_SESSION['LAST_ACTIVE'])/60) . " minutes.";$_SESSION['LAST_ACTIVE'] = date("ymdHis");[/code]But sometimes I get alot more minutes, than he's really logged in. I'm not sure if it's a good idea, to include even year, month, date, but for example if the time is 23:45 and then it goes to 00:15, it will screw up! Any suggestions how to make this work? Thank you! Quote Link to comment Share on other sites More sharing options...
Asheeown Posted January 8, 2007 Share Posted January 8, 2007 A lowercase g shows the hour (12 hour format) and a lowercase i shows the minutes(with leading zeros)[code]echo "You have been logged in for " . round((date("gi") - $_SESSION['LAST_ACTIVE'])/60) . " minutes.";$_SESSION['LAST_ACTIVE'] = date("gi");\[/code] Quote Link to comment Share on other sites More sharing options...
chronister Posted January 8, 2007 Share Posted January 8, 2007 For this use unix timestamps for your math with time, and then convert the timestamp at the time you display. This way, it won't matter if you are going from 23:45 to 00:15, the seconds in between are going to be the same no matter what.I would do all the calculations before I do the echo so that the echo is as simple as possible.[code]$timeloggedin= (time() - $_SESSION['LAST_ACTIVE]) / 60 /* would take now[time()] - lastactive time then divide the results by 60 */echo "You have been logged in for $timeloggedin";[/code]I found a function script on google that will convert the seconds difference into a time like 1:15:23 for 1 hour 15 minutes 23 seconds. If you cannot locate it lemme know and I will give it to you if you wantIs this kind of what you are after?? Hope it helps some Quote Link to comment Share on other sites More sharing options...
Hyaku_ Posted January 8, 2007 Author Share Posted January 8, 2007 Thanks alot!![code]int time ( void )Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). [/code]That is what I needed! Thanks! Quote Link to comment 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.