Save elapsed Session time to DB???

Results 1 to 2 of 2

Thread: Save elapsed Session time to DB???

  1. #1
    william Guest

    Default Save elapsed Session time to DB???

    How do I store the elapsed Session time after a Session ends in a DB?<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    1,671

    Default RE: Save elapsed Session time to DB???

    I would use the global.asa session_OnStart and session_OnEnd subs<BR><BR>I will skip the ado details...Also not syntax checked...<BR><BR>sub session_OnStart()<BR>**set conn.....<BR>**conn.open<BR>**sql="INSERT INTO MyTable(whatsession, Logged_in_at)" & _<BR>**"VALUES (&#039" & session.SessionID & "&#039,*" & now() & ")" <BR>**conn.execute sql<BR>end sub<BR><BR>sub session_OnEnd<BR>**set conn.....<BR>**conn.open<BR>**sql="UPDATE MyTable SET Session_ended_at = now() " & _<BR>**"WHERE WHATSESSION =&#039" & session.SessionID & "&#039 AND " & _<BR>**"Session_ended_at= &#039&#039"<BR>**conn.execute sql<BR>end sub<BR><BR>Basically I assumed a simple 3 field table that has whatsession (text), Logged_in_at (date/time)and Session_ended_at (Date/time)as the fields. In reality you would probably want some other fields like username, etc...<BR>Also sessionIDs are not 100% unique so I added the AND Session_ended_at= &#039&#039 (that is = two ticks not a quote) so if there happens to be two identical sessionIDs, it is unlikely they would both ever be open at the same time. Not a true "Key" but what else are you going to get once the user is gone (along with his cookies). <BR><BR>A simple view/query of this table could produce the elapsed time by doing the math. Alternately you could do the math in the on session_onEnd. <BR><BR>Remember, unless you session.abandon the user the session will actualy end some time after they leave your site (usually 20 minut default in IIS) so keep that in mind. You may want to subtract out the actual session timeout you have on your server.<BR><BR>Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •