clown[NOR] Posted May 15, 2007 Share Posted May 15, 2007 well... I've tried to make this work now, but it wasn't as easy as I thought... I'm trying to see how long a user has been logged in... this is what I've got so far... <?php function getOnlineTime($user,$sid,$axx) { dbConn(); $cTime = strtotime(date("H:i:s")); $query = "SELECT * FROM `news_users` WHERE email ='".$user."' AND sid ='".$sid."' AND access ='".$axx."' LIMIT 1"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } $dbField = mysql_fetch_assoc($result); $logintime = strtotime($dbField['logintime']); $time_online = $logintime-$cTime; $time_online = date("H:i:s", $time_online); $time_online = explode(":", $time_online); return $time_online[0].'t '.$time_online[1].'m '.$time_online[2].'s'; } ?> but it kinda didn't work as I hoped.. what it does now is that it counts down something i'm not sure what it's counting down to... any ideas on how to fix my problem? Thanks In Advance - Clown Link to comment https://forums.phpfreaks.com/topic/51517-help-get-online-time/ Share on other sites More sharing options...
taith Posted May 15, 2007 Share Posted May 15, 2007 $_SESSION[signedintime]=time(); #put me on login page $dif=time()-$_SESSION[signedintime]; while($dif>=60){ $minutes++; $dif-=60; } then just continue on for hours, days, weeks, monts... whatever :-) Link to comment https://forums.phpfreaks.com/topic/51517-help-get-online-time/#findComment-253719 Share on other sites More sharing options...
clown[NOR] Posted May 15, 2007 Author Share Posted May 15, 2007 hmm... then just continue on for hours, days, weeks, monts... whatever :-) can you please explain that a little bit closer please? TIA - Clown Link to comment https://forums.phpfreaks.com/topic/51517-help-get-online-time/#findComment-253732 Share on other sites More sharing options...
taith Posted May 15, 2007 Share Posted May 15, 2007 $dif=time()-$_SESSION[signedintime]; $hours=0; while($dif>=3600){ $hours++; $dif-=3600; } $minutes=0; while($dif>=60){ $minutes++; $dif-=60; } echo "You have been online for $hours hours, $minutes minutes and $dif seconds"; Link to comment https://forums.phpfreaks.com/topic/51517-help-get-online-time/#findComment-253733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.