Jump to content

[SOLVED] check how long user has been logged in


Hyaku_

Recommended Posts

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!
Link to comment
Share on other sites

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 want

Is this kind of what you are after?? Hope it helps some

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.