I am writing a usersystem and as a statistic available for all my users I want to be able to provide them with the amount of hours they’ve been active on my website.
my original idea as to how to do this was:
user loads a page, and a record for the user is stored in a SQL table called accessLog
*user loads another page, sql query runs to see when they last visited a page*
if the user visited a page within the past two minutes, update their user account and add the time spent online
*insert a new record into accessLog*
however this would mean adding a potential of 4 additional queries to every single page of my website, which seems slow. I was thinking, there has got to be a more efficient way of tracking user activity online that I’m clearly too stupid to see!
My way of doing this is simple:
In this way, I can keep track of users accurately to the minute. Just divide by 60 to get the hours.