简体   繁体   中英

Record the time a user was logged in with Authlogic

I need to add a report in my app of how much time a User is logged in.

I know it will not be accurate because if the User closes the browser, the session will live around 30 minutes more.

But with all the limitations, how do I know when a session has expired and record that time even if there is no request present?

As far as managing the session, the means of how you would access it could vary. But one way you can probably track time is to record the time in a database field whenever the user logs in. Then if the user logs out, record the log out time. Then add the difference (log out time - log in time) to another total time field. As for session expiring, you can probably assume that it expires after 30 minutes. So the next time the user logs in, if the "log out time" field is blank, then assume the last block of time spent is the lesser of: The new "log in time" - "last log in time" or 30 minutes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM