title: Total time registered user have been online
body: <p>I am right now programming a community in PHP, but i'm stuck, as i can't figure out, how to see how long my users have spent on the site. It should be showed on their profile, such as: "This user has spent 10 hours and 10 minutes on sitename". But i have no idea, how i should make this!</p>
  
  <p>I think of adding a row to my users table (In my MySQL database) called 'last_visit_time' to store the time the user last time visited a site on my website and one called 'total_time' to store total time spent online.</p>
  
  <p>Then everytime a user loads a page, it first check if you'r logged in. Then if you are, it first checks if('last_visit_time' + 2 minutes >= $current_time) then, if that is true, it add the difference of 'last_visit_time' and $current_time to the 'total_time' row. After that, it updates the 'last_visit_time' to the currently time.</p>
  
  <p>This will give a 2 minutes tolerence, for users to visit a new page - and then it add the time spent on the previous page (If it's under 2 minutes). As what i can figure out, there is no way the users can cheat with this script, because you will be gained nothing by spam-updating the pages or visiting the page in 2 windows (On same account).</p>
  
  <p>But how can you actually get the difference between currently time, and last_visit_time, and check if there has passed more than 2 minutes! Or should i make this a different way?</p>
  
  <p>I'm quite open for suggestions and especially help, as it is needed very much.</p>
  
  <p>Thank you!</p>