CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Tracking user logins/logouts

Print topic Send  topic

Author Message
peterr


Posts: 5971
Posted: 02/06/2004, 5:26 PM

Due to several related questions recently, here is sample implementation based on BookStore example with MS Access:

1. Create the Store solution/example:
http://docs.codecharge.com/studio/html/ProgrammingTechn...SSolutions.html

2. Modify the "Intranet" database example provided with CCS and used in the example, by adding the following fields to the "users" table:
is_online (Yes/No field in MS Access, Boolean otherwise)
date_login (Date/Time field)

3. Open the Login page and navigate to the "DoLogin" button where you will find "Login" action assigned to the "On Click" event of the button. Add the following custom code to the same "On Click" event (you will have both "Login" action and Custom Code assigned to the same event):
Dim Connection  
Set Connection = New clsDBinternet  
Connection.Open  
If Login_DoLogin_OnClick = True And CCGetUserID<>"" Then Connection.Execute("UPDATE users SET is_online=True, date_login=#" & Now() & "# WHERE user_id=" & CCGetUserID)  
Connection.Close  
Set Connection = Nothing
This is all that is needed to track user logins.

To add tracking of user logouts:
4. Open the Login page and double-click on the "Logout" action assigned to the "After Initialize" event of the page. Once in the Code mode, replace the code that you find there with this version:
If NOT IsEmpty(CCGetParam("Logout", Empty)) Then  
  Set Connection = New clsDBinternet  
  Connection.Open  
  Connection.Execute("UPDATE users SET is_online=False WHERE user_id=" & CCGetUserID)  
  Connection.Close  
  Set Connection = Nothing  
  CCLogoutUser  
End If
Note: the Logout is performed by directing users to the Login page via a URL containing "Logout=something". For example:
http://localhost/BookStore/login.asp?Logout=1

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
marcwolf


Posts: 361
Posted: 02/08/2004, 9:03 PM

Hi Peter.

Thats works well, and you can add all sorts of additional things like login date, update a collection with who is online at that time etc..

But one thing I have found no solution for yet.. is if the user decides to close the browser session and not log off properly..

Possible solutiosn for this range from a simple script run periodically from the global.asa to auto log off after no actvity and that is based on a simple update on each page the user accesses (set useraccess=now where userid = xxx). And any user who has not touched a page for X hours is reset.

To the more complex using the Server.isclientconnected and trying a reverse lookup from server to client to see is the client is still there.
This can be put into a frame can refreshed from the browser every 5 mins. It can also keep alive session that the user has left open due to taking phone calls etc.

But it is not perfect...

Any suggestions..





_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message
peterr


Posts: 5971
Posted: 02/08/2004, 10:36 PM

You're right. Due to the nature of the Web this is as "clean" as it gets in any Web application.
Couple additional solutions might be:
a) Open the Logout page automatically via OnClose event - just like various Websites do when you try to close them. It might be even possible to open such pop-up page, log the user out and close the page, all in the background.
Although in case a user has several browser windows open and closes only one of them, a better way may be to open a popup page that only informs users to Logout. Though this can also be annoying if users often work in multiple browser windows.
b) Use the last login date (or last activity date) in addition to "Active=True" when filtering records to display active users. Therefore the database can have Active flag set to "True" but based on the last activity date you can display the status for this user as "not logged in".
The biggest issue with this that you'd probably need to track the user's activity basically on every page, because the login date is not exactly related to how long the user can be on the site.
c) respect users' privacy and accept if they close their browser then posibly they don't want you to know that they no longer are on your Website :-) Unless this is a business environment, in which case probably any of the other solutions would be as good as it gets.

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
DRAG_RACER
Posted: 02/09/2004, 3:40 AM

Hello


I'm using ASP

where is my mistake ?

Function Login_DoLogin_OnClick() 'Login_DoLogin_OnClick @9-FA16D195

'Custom Code @14-73254650
' -------------------------
Dim Connection
Set Connection = New clsDBConnection1
Connection.Open
If Login_DoLogin_OnClick = True And CCGetUserID<>"" Then Connection.Execute("UPDATE KULLANICI SET online=True, giris=#" & Now() & "# WHERE ID=" & CCGetUserID)
Connection.Close
Set Connection = Nothing
' -------------------------
'End Custom Code


'Login @10-A0860347
With Login
If NOT CCLoginUser(.login.Value, .password.Value) Then
.Errors.addError("Login or Password is incorrect.")
Login_DoLogin_OnClick = False
.password.Value = ""
Else
If Not IsEmpty(CCGetParam("ret_link", Empty)) Then _
Redirect = CCGetParam("ret_link", Empty)
Login_DoLogin_OnClick = True
End If
End With
'End Login

Quote peterr:
Due to several related questions recently, here is sample implementation based on BookStore example with MS Access:

1. Create the Store solution/example:
http://docs.codecharge.com/studio/html/ProgrammingTechn...SSolutions.html

2. Modify the "Intranet" database example provided with CCS and used in the example, by adding the following fields to the "users" table:
is_online (Yes/No field in MS Access, Boolean otherwise)
date_login (Date/Time field)

3. Open the Login page and navigate to the "DoLogin" button where you will find "Login" action assigned to the "On Click" event of the button. Add the following custom code to the same "On Click" event (you will have both "Login" action and Custom Code assigned to the same event):
Dim Connection  
Set Connection = New clsDBinternet  
Connection.Open  
If Login_DoLogin_OnClick = True And CCGetUserID<>"" Then Connection.Execute("UPDATE users SET is_online=True, date_login=#" & Now() & "# WHERE user_id=" & CCGetUserID)  
Connection.Close  
Set Connection = Nothing
This is all that is needed to track user logins.

To add tracking of user logouts:
4. Open the Login page and double-click on the "Logout" action assigned to the "After Initialize" event of the page. Once in the Code mode, replace the code that you find there with this version:
If NOT IsEmpty(CCGetParam("Logout", Empty)) Then  
  Set Connection = New clsDBinternet  
  Connection.Open  
  Connection.Execute("UPDATE users SET is_online=False WHERE user_id=" & CCGetUserID)  
  Connection.Close  
  Set Connection = Nothing  
  CCLogoutUser  
End If
Note: the Logout is performed by directing users to the Login page via a URL containing "Logout=something". For example:
http://localhost/BookStore/login.asp?Logout=1

peterr


Posts: 5971
Posted: 02/09/2004, 2:55 PM

You can debug your code, or contact our support at http://support.codecharge.com

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Jason Bragg
Posted: 07/26/2005, 7:59 AM

When trying this code I get an error that Variable is undefined New clsDBinternet. What am I doing wrong?

I'm using the Store Solution example..

Thanks,
Jason

Nicole

Posts: 586
Posted: 07/27/2005, 2:50 AM

Jason,
I suppose that you get the error on this code lines
Set Connection = New clsDBinternet
In common the code is
Set Connection = New clsDB<connection_name>
If your database connection name is different from "internet" you need to use your custom connection name in the code

_________________
Regards,
Nicole
View profile  Send private message
Jason Bragg
Posted: 07/27/2005, 5:23 AM

Nicole,

This fixed the problem!

Now I need to figure out how to get it to place multiple login and logout times for each time a user logs in or out. Any thoughts on that? I'm kind of new to ASP.

Thanks!
Jason

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.