#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0

    Session Timeout not deleting from database


    Folks,
    I have a small problem.
    using the code below(which seems common). When user times out it is suppose to delete the session from the database, but it is not. I need a little understanding on the StrOnlineTimedOut line.

    I am wondering if it is not deleting the session because it is comparing dates and not the hours, minutes, and seconds.

    Most of my users who go to this page and timeout shouldn't be there for more than 10 mins. I want to remove them from the database and re-login. Any help and understanding would be great

    <!--#include file='includes/dbconnection.inc'-->
    <%
    onlinedate = now()
    OnlineUserIp = Request.ServerVariables("REMOTE_ADDR")
    strUserID = Replace(Session("username"), "'", "''")
    strTimeout = 5
    StrOnlineTimedout = dateadd("n",-strtimeout*3,onlinedate)
    StrSql = "Select * From active_users Where User_ID='" & strUserID & "'"
    Set rs1 = adoCon.Execute (StrSql)
    if rs1.eof then
    'Add user to database because they dont exist
    StrSql = "INSERT INTO active_users (Logon_time,User_ip,Last_Seen,Last_Page,User_ID) " &_
    "VALUES ('" & onlinedate & "','" & OnlineUserIp & "','" & now() & "','" &_
    request.servervariables("path_info") & "','" & strUserID & "')"
    adoCon.Execute (StrSql)
    else
    'There Still active so lets update their info
    StrSql = "UPDATE active_users SET Last_Seen='" & now() & "', Last_Page='" &_
    request.servervariables("path_info") & "' WHERE User_ID='" & strUserID & "'"
    adoCon.execute (StrSql)
    end if
    'Remove Users Who Have Timed Out
    StrSql = "DELETE FROM active_users WHERE Last_Seen < #" & StrOnlineTimedout &"#"
    adoCon.execute (StrSql)

    %>

    Thanks,
    Plasmagrid
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,428
    Rep Power
    4539
    What debug steps have you taken with what results?
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    Originally Posted by Doug G
    What debug steps have you taken with what results?
    I have set the timeout limits lower and still does not release the session, I can open the database and manually remove the entry and log back in.
  6. #4
  7. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,428
    Rep Power
    4539
    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.
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    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 &"#"
    adoCon.execute (StrSql)
    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 & "'"
    adoCon.execute (StrSqlUp)

    else
    '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 & "')"
    adoCon.Execute (StrSqlAdd)

    end if


    %>


    Down further on the page is the login form. There is nothing else fancy in the page(no other pertinent code)
    <td>

    <span style="background-color:#FFFFFF; padding:3px 5px 3px 5px;">Username:</span>&nbsp;<input type="text" name="txtUsername">
    <br><br>
    <span style="background-color:#FFFFFF; padding:3px 5px 3px 5px;">Password:</span>&nbsp;<input type="password" name="txtUserPass">
    <br><br>
    <span style="margin-right:50px;background-color:#FFFFFF;font-size:12px;padding:3px 5px 3px 5px;"><a href="HELPmeURL" target="_blank">Login Help ?</a>&nbsp;</span><span style="margin-left:45px;"><input type="submit" value="Login" name="submit"></span>
    <br><br>
    <span style="font-size:12px;font-weight:bold;background-color:#FFFFFF;padding:3px 5px 3px 5px;"><a href="registerURL">Register an Account ?</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="LostURL">Forgot Password ? </a></span>


    </td>

IMN logo majestic logo threadwatch logo seochat tools logo