unsider Posted July 11, 2008 Share Posted July 11, 2008 I'm assuming you would create a timestamp for the user when he registers? And the timestamp would track when the session was last active/ ended, for that particular user. Is converting a time stamp into a last active on: jan 4, 2006 as simple as a echoing the timestamp in a date format? If I'm not making sense or any of what I said is incorrect, please correct me, I'm here to learn. I've written a little piece of code, can someone explain the 'last active' concept to me through this code (if possible)? Also keep in mind this was written quickly, I'm tired, and probably gonna check this in the morning. So feel free to correct ANY mistakes I might have made. Thanks. <?php function timestamp(){ global $database; $q = "SELECT timestamp" ."FROM "user" ORDER BY timestamp DESC, timestamp"; $result = $database->query($q); $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } $time = mysql_result($result,"timestamp"); echo "$time"; } ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 11, 2008 Share Posted July 11, 2008 minor error. change this: $q = "SELECT timestamp" ."FROM "user" ORDER BY timestamp DESC, timestamp"; to this: $q = "SELECT timestamp" $q .= " FROM `user` ORDER BY timestamp DESC"; Regards ACE Quote Link to comment Share on other sites More sharing options...
corbin Posted July 11, 2008 Share Posted July 11, 2008 $q = "SELECT timestamp" ."FROM "user" ORDER BY timestamp DESC, timestamp"; Is entirely valid. The problem is that you're not updating the timestamp. Everytime the user requests a page, you know they're active, yes? That would mean that you should update the timestamp then. Quote Link to comment Share on other sites More sharing options...
unsider Posted July 11, 2008 Author Share Posted July 11, 2008 Well I am updating the timestamp (in my real project ), if the user is logged in that is, session values set, etc.., and requests a page, I guess now I'm just asking how I would output the last recorded timestamp of that particular user in a.... Last Active On: Feb 11, 2030 fashion. And thanks for clarifying that, I wasn't absolutely sure if that SQL was valid. Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 11, 2008 Share Posted July 11, 2008 i have a field in my database that has a timestamp in it the time stamp is updated everytime the user presses login or access a page and it detects an auto login cookie and no session setup. if you want it to just record every time a user views a page add a line at the top of your code after you authenticate the user <?php mysql_query("UPDATE `users` (`last_active`) VALUES ('".time()."');"); ?> Scott. Quote Link to comment Share on other sites More sharing options...
corbin Posted July 11, 2008 Share Posted July 11, 2008 http://php.net/date if it's a unix timestamp. These might also help: http://dev.mysql.com/doc/refman/5.0/en/datetime.html http://php.net/strtotime Quote Link to comment Share on other sites More sharing options...
unsider Posted July 11, 2008 Author Share Posted July 11, 2008 It's a Unix timestamp that I need to convert to a date. Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 12, 2008 Share Posted July 12, 2008 have you looked at date() http://php.net/date if it's a unix timestamp. Scott. 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.