ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 20th, 2012, 07:27 AM
plasmagrid plasmagrid is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 plasmagrid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 32 sec
Reputation 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

Reply With Quote
  #2  
Old July 20th, 2012, 08:19 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
What debug steps have you taken with what results?
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

Reply With Quote
  #3  
Old July 22nd, 2012, 05:58 PM
plasmagrid plasmagrid is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 plasmagrid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 32 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
  #4  
Old July 22nd, 2012, 10:33 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
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.

Reply With Quote
  #5  
Old July 25th, 2012, 06:07 PM
plasmagrid plasmagrid is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 plasmagrid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 32 sec
Reputation Power: 0
Quote:
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>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Session Timeout not deleting from database

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap