gish Posted January 5, 2009 Share Posted January 5, 2009 hi phpfreaks I know that the logged in time above would have to use at database but does it use a time() function. the code I have below must be very wrong i know. right now I get either 0 or 14. All I want to do right now is when the page refreshes it will tell the user how long they have been on the site. I know I can do this with javascript but have bigger plans for the outcome that involve php. I just am at a loss to know how to go about it. does anyone have ideas $current_time = date("H:i:s"); $_SESSION['session_time'] = $current_time - $_SESSION['session_time']; echo " Time Logged On: " . $insert . $_SESSION['session_time'] . " </span>" ; Link to comment https://forums.phpfreaks.com/topic/139485-logged-in-time/ Share on other sites More sharing options...
emehrkay Posted January 5, 2009 Share Posted January 5, 2009 You're doing math on a string. $current_time = date("H:i:s"); // '24:60:60' It may be easier to use time() as it gives you seconds. You can convert that to an integer by doing (int) $var or by simply doing math with it Link to comment https://forums.phpfreaks.com/topic/139485-logged-in-time/#findComment-729686 Share on other sites More sharing options...
gish Posted January 5, 2009 Author Share Posted January 5, 2009 I have been doing some reading and I have done the following the time keep changing but the int is not working so is the code below on the right tract $time=time(); echo $time; // int turns it string into a number $num_time = (int)$time; $num_time = $_SESSION['session_time']; echo " Time Logged On: " . $insert . $_SESSION['session_time'] . " </span>" ; Link to comment https://forums.phpfreaks.com/topic/139485-logged-in-time/#findComment-729707 Share on other sites More sharing options...
emehrkay Posted January 5, 2009 Share Posted January 5, 2009 What format is $_SESSION['session_time']; in? Link to comment https://forums.phpfreaks.com/topic/139485-logged-in-time/#findComment-729891 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.