MrXander Posted July 16, 2007 Share Posted July 16, 2007 Okay, well thanks to lococobra in my last thread, he kindly put together a code to determine a users last action depening on a timestamp, his code was: <?php $lastActive = time() - $lastTime if($lastActive >= 60){ //More than 60 seconds ago $lastActive = intval($lastActive/60); $timeType = "Minutes"; } else { $timeType = "Seconds"; } echo 'User was active '.$lastActive.' '.$timeType.' ago.'; ?> But now, can anyone tell me, if this runs over into hours or weeks, how can I add that too? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 16, 2007 Share Posted July 16, 2007 You just have to find out how many seconds for everything. <?php $lastActive = time() - $lastTime; if($lastActive >= 60 && $lastActive < 3600){ //More than 60 seconds ago $lastActive = intval($lastActive/60); $timeType = "Minute(s)"; } else if ($lastActive >= 3600 && $lastActive < 86400){ $lastActive = intval($lastActive/3600); $timeType = "Hour(s)"; } else if ($lastActive >= 86400 && $lastActive < 864800){ $lastActive = intval($lastActive/86400); $timeType = "Day(s)"; } else if ($lastActive >= 864800 && $lastActive < 3459200){ $lastActive = intval($lastActive/864800); $timeType = "Week(s)"; } else if ($lastActive >= 3459200){ $lastActive = intval($lastActive/3459200); $timeType = "Month(s)"; } else { $timeType = "Seconds"; } echo 'User was active '.$lastActive.' '.$timeType.' ago.'; ?> I will keep adding....hold on. EDIT: Okay, that should work for you =] Quote Link to comment Share on other sites More sharing options...
MrXander Posted July 16, 2007 Author Share Posted July 16, 2007 You just have to find out how many seconds for everything. <?php $lastActive = time() - $lastTime; if($lastActive >= 60 && $lastActive < 3600){ //More than 60 seconds ago $lastActive = intval($lastActive/60); $timeType = "Minute(s)"; } else if ($lastActive >= 3600 && $lastActive < 86400){ $lastActive = intval($lastActive/3600); $timeType = "Hour(s)"; } else if ($lastActive >= 86400 && $lastActive < 864800){ $lastActive = intval($lastActive/86400); $timeType = "Day(s)"; } else if ($lastActive >= 864800 && $lastActive < 3459200){ $lastActive = intval($lastActive/864800); $timeType = "Week(s)"; } else if ($lastActive >= 3459200){ $lastActive = intval($lastActive/3459200); $timeType = "Month(s)"; } else { $timeType = "Seconds"; } echo 'User was active '.$lastActive.' '.$timeType.' ago.'; ?> I will keep adding....hold on. EDIT: Okay, that should work for you =] That is absolutely perfect. Thank you!! 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.