Skip to main content
Known Participant
October 20, 2009
Answered

track user time logged in

  • October 20, 2009
  • 1 reply
  • 929 views

I need to build a simple login and have a visitor view a movie clip then log out. I need to store in a database how long the user was logged in using asp. Can anyone help? I can build the login i just need to know how to log users time logged in.

This topic has been closed for replies.
Correct answer bregent

The part to code the time stamp for both and the math code


Store the current time at login in a session variable:

Session("logintime")=Now

Calculate the elapsed time in seconds:

DateDiff("s",Session("logintime"),now)

1 reply

Participating Frequently
October 20, 2009

When they log in, store the date/time in a session variable. When they log out, calculate the difference between the current and stored time, and then insert that into your database.

Known Participant
October 21, 2009

Can u provide a code sample?

Participating Frequently
October 21, 2009

I don't have a sample. IMO, it's not worth the trouble since most people don't log off anyway --they just leave the site or close the browser -- so the log off script will never run. If you need something more robust you would have to investigate using the global.asa file to code session events. Are you familiar with global.asa ?