Originally Posted by Doug G
I don't understand your code. ASP sessions are terminated in code by the Session.Abandon method and if a user session times out it will fire an event in code you create in global.asa. global.asa code is the only place you can capture a session terminating event. I don't see what is firing off your code.
Also, vbscript has a few date-related functions you should use for date/time comparisons like dateadd(), etc. You can find the available functions in the msdn library documentation for vbscript.
This is in the header section of the login page and should theoretically fire off as soon as page is loaded.
I am looking to try and make this code delete the row in the table if the user is back at this page(whether timed out or clicked logout) to check the user id and delete from the table active_users
Been trying to get this to work for a week and I am obviously missing something.
I even reformatted the code :
onlinedate = now()
OnlineUserIp = Request.ServerVariables("REMOTE_ADDR")
strUserID = Replace(Session("username"), "'", "''")
strTimeout = 2
StrOnlineTimedout = dateadd("n",-strtimeout*3,onlinedate)
StrSqlUser = "Select * From active_users Where User_ID='" & strUserID & "'"
Set rs1 = adoCon.Execute (StrSqlUser)
'Remove Users Who Have Timed Out
StrSql = "DELETE * FROM active_users WHERE Last_Seen < #" & StrOnlineTimedout &"#"
if NOT rs1.eof then
'There Still active so lets update their info
StrSqlUp = "UPDATE active_users SET Last_Seen='" & now() & "', Last_Page='" &_
request.servervariables("path_info") & "' WHERE User_ID='" & strUserID & "'"
'Add user to database because they dont exist
StrSqlAdd = "INSERT INTO active_users (Logon_time,User_ip,Last_Seen,Last_Page,User_ID) " &_
"VALUES ('" & onlinedate & "','" & OnlineUserIp & "','" & now() & "','" &_
request.servervariables("path_info") & "','" & strUserID & "')"
Down further on the page is the login form. There is nothing else fancy in the page(no other pertinent code)
<span style="background-color:#FFFFFF; padding:3px 5px 3px 5px;">Username:</span> <input type="text" name="txtUsername">
<span style="background-color:#FFFFFF; padding:3px 5px 3px 5px;">Password:</span> <input type="password" name="txtUserPass">
<span style="margin-right:50px;background-color:#FFFFFF;font-size:12px;padding:3px 5px 3px 5px;"><a href="HELPmeURL" target="_blank">Login Help ?</a> </span><span style="margin-left:45px;"><input type="submit" value="Login" name="submit"></span>
<span style="font-size:12px;font-weight:bold;background-color:#FFFFFF;padding:3px 5px 3px 5px;"><a href="registerURL">Register an Account ?</a> <a href="LostURL">Forgot Password ? </a></span>