Are you looking to use this in a report for Admins? Or to display it to the users?
If it is an admin only report you can probably get a decent idea from processing your web server logs, without doing any extra coding.
Other way is to track it by a cookie, and every time the user hits a page, update the time browsed based on that cookie which has a start date/time saved in it. This would be a session cookie which expires after not being used for a set period of time which would cover the person leaving the site.
I used a session cookie because it normally has a short expiration time. But you could use the same method with a cookie which does not expire for a longer period. But you would have to update the code to handle when they go inactive for a long period. (aka the close the browser and go to bed, and open it again in the morning) You would have to code in what you think is a safe delay, which you can add to the login time before counting it as a new login time.