Jump to content

Help: get online time


clown[NOR]

Recommended Posts

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
Share on other sites

$_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
Share on other sites

$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
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.