Copy link to clipboard
Copied
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.
Store the current time at login in a session variable:
Session("logintime")=Now
Calculate the elapsed time in seconds:
DateDiff("s",Session("logintime"),now)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Can u provide a code sample?
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
No I'm not familiar with it. And on the site the user will have to log out its a corporate intranet and in order to get credit its mandatory. Its for a certification class.
Copy link to clipboard
Copied
Ok, then that should work. What part are you having problems with?
Reading/writing sessions?
SQL insert statement?
Date/time calculations?
What scripting language are you using?
Copy link to clipboard
Copied
The part to code the time stamp for both and the math code
Copy link to clipboard
Copied
Store the current time at login in a session variable:
Session("logintime")=Now
Calculate the elapsed time in seconds:
DateDiff("s",Session("logintime"),now)