Jump to content

[SOLVED] Last Question :)


MrXander

Recommended Posts

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?

Link to comment
Share on other sites

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 =]

Link to comment
Share on other sites

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!!

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.