|
|||
Hi,
I developed a user management system in 2002 in ASP, but the project was abandoned and was only 70% complete. To answer your question, it is possible to do it without the global.asa by manipulating that file and saving it as a standard asp file. For this example, I’ll name it global.asp. Global.asp Code:
Session("sid") = Session.SessionID
v_user = Split(Application("Session_Usr"), "|^|")
v_guest = Split(Application("Session_Gue"), "|^|")
If UBound(v_user) = -1 Then
t_online = UBound(v_guest)
ElseIf UBound(v_guest) = -1 Then
t_online = UBound(v_user)
ElseIf UBound(v_user) = -1 And UBound(v_guest) = -1 Then
t_online = 0
Else
t_online = (UBound(v_user)) + (UBound(v_guest))
End If
Sub User_Online()
If Session("user") <> "" Then
For i = 0 To UBound(v_user)
If v_user(i) = Session("user") Then new_online = 1 End If
Next
If new_online <> 1 Then
Application.Lock
Application("Session_Usr") = Application("Session_Usr") & "|^|" & Session("user")
Application.UnLock
End If
Else
For j = 0 To UBound(v_guest)
If v_guest(j) = Session("sid") Then new_gonline = 1 End If
Next
If new_gonline <> 1 Then
Application.Lock
Application("Session_Gue") = Application("Session_Gue") & "|^|" & Session("sid")
Application.UnLock
End If
End If
End Sub
Sub Logout()
Application.Lock
Application("Session_Usr") = Replace(Application("Session_Usr"), "|^|" & abd_usr, "")
Application(abd_usr & "_loc") = ""
Application(abd_usr & "_tim") = ""
Application.UnLock
If Request.ServerVariables("SERVER_SOFTWARE") = "Microsoft-IIS/5.0." Then
Application.Contents.Remove abd_usr & "_loc"
Application.Contents.Remove abd_usr & "_tim"
If Application("Session_Usr") = "" Then
Application.Contents.Remove "Session_Usr"
End If
End If
End Sub
If Session("user") <> "" Then
Application.Lock
If Request.ServerVariables("SERVER_PORT_SECURE") = 0 Then
Application(Session("user") & "_loc") = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")
Else
Application(Session("user") & "_loc") = "https://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")
End If
Application(Session("user") & "_tim") = Now()
Application.UnLock
Else
Application.Lock
Application(Session("sid") & "_gtim") = Now()
Application.UnLock
End If
For x = 0 To UBound(v_user)
If v_user(x) <> "" Then
If Application(v_user(x) & "_tim") <= DateAdd("n", -(App_Timeout), Now()) Then
Application.Lock
Application("Session_Usr") = Replace(Application("Session_Usr"), "|^|" & v_user(x), "")
Application(v_user(x) & "_loc") = ""
Application(v_user(x) & "_tim") = ""
Application.UnLock
If Request.ServerVariables("SERVER_SOFTWARE") = "Microsoft-IIS/5.0." Then
Application.Contents.Remove v_user(x) & "_loc"
Application.Contents.Remove v_user(x) & "_tim"
If Application("Session_Usr") = "" Then
Application.Contents.Remove "Session_Usr"
End If
End If
End If
End If
Next
For y = 0 To UBound(v_guest)
If v_guest(y) <> "" Then
If Application(v_guest(y) & "_gtim") <= DateAdd("n", -(App_Timeout), Now()) Then
Application.Lock
Application("Session_Gue") = Replace(Application("Session_Gue"), "|^|" & v_guest(y), "")
Application(v_guest(y) & "_gtim") = ""
Application.UnLock
If Request.ServerVariables("SERVER_SOFTWARE") = "Microsoft-IIS/5.0." Then
Application.Contents.Remove v_guest(y) & "_gtim"
If Application("Session_Gue") = "" Then
Application.Contents.Remove "Session_Gue"
End If
End If
End If
End If
Next
Include in all pages that you would like to track: <!--#include file="global.asp"--> Total Users Online Code:
<% If t_online = -1 Or t_online = -2 Then %>0<% Else Response.Write t_online End If %> Code:
<% If UBound(v_user) = -1 Then %>0<% Else Response.Write UBound(v_user) End If %> Code:
<% If UBound(v_guest) = -1 Then %>0<% Else Response.Write UBound(v_guest) End If %> |
|
|||
If you had access to global.asa, this is a shorter and easier method.
Global.asa Code:
<script language=VBScript runat=Server>
Sub Session_OnStart()
Application.Lock
Application("Sessions") = Application("Sessions") + 1
Application.UnLock
End Sub
Sub Session_OnEnd()
Application.Lock
Application("Sessions") = Application("Sessions") - 1
Application.UnLock
End Sub
</script>
Some.asp Code:
<% Response.Write Application("Sessions") %>
1) This uses global.asa the earlier one doesn't 2) This script can only output the number of active users only. The earlier once can track and output Number of Active users online, guests online, members online and current location of guest/member. 3) The ASP script above can be trimmed down to only a few lines of code if you wanted only a simple script that trackec only the number of active users and nothing else. 4) The main reason why the ASP script is longer is because you cannot use Session_OnEnd() meaning that you would have to terminate the session using a manual process, which in the above case was handled in the lines, 'For x & For y' Hope this helps |
|
||||
I already did that one, the one with only the number of users. But whats the method to store active user list using your global asa? I would like to get this clear : are variables declared in global.asa can be recognized in your normal asp page? can i insert normal asp codes in my global.asa (for instance database insertion)?. thanks.
|
|
|||
Yeah, you could put ASP in the global asa. But you should only put things which you want to make global - items which are reused in most if not all of your asp pages. A database connection would be good.
To show members online, you could use something like the following: Code:
Sub Session_OnStart()
Application.Lock
Application("Sessions") = Application("Sessions") + 1
-- you if statement, if user is member and logged in --
Application("Session_Usr") = Application("Session_Usr") & "|^|" & Session("user")
-- end if --
Application.UnLock
End Sub
You would also need to make adjustments to Session_OnEnd() to remove the active user from the list when they log out or exit the site. |
|
|||
|
||||
Correct me if i am wrong, but shouldnt we keep track of the users by some kinde of storage, which in this case, possibly, an array or database insertion, or perhaps an application variable with an increasing parameter
eg: sub Session on start count = count + 1 Application("user")&count = session("id") end sub then you'd display em like : while count > 0 Response.Write application("user")&count Wend That's was my original idea. BUt another guy in another forum suggested database insertion, which i thoughtrather feasible than my original idea (which didnt work anyway). I tried, ana initially failed. i havent tried to my fullest, but i have one question: If it includes database insertion, do i have to keep the connection open or do i have to keep em connected. And if i do, is it in applicationon start or session on start? Thanks for your time. Appreciate it. |
|
|||
Well, your idea and the code (global.asa) I gave above is about same except the code I gave has Application.Lock and Application.UnLock which is required.
Since Application variables are stored in memory, you require Application.Lock to append the current Application Variable in memory. Without Application.Lock, you would be creating a new or overwriting the Application Variable each time. The Application variable is already a storage method. As for database intergration - don't do it. Integrating it with a database would be making a simple task difficult. Work with the Application variables. I suggest having only two Application variables, 1 to count the number of users, and 1 to record the users. Or, if you can wait, I'll try to make something for you sometime this week if i have a bit of spare time. |
|
||||
Thanks sufy, appreciate it. But gotta make one thing clear, are you saying one Application variable can hold more than one value?
Application("Session_Usr") = Application("Session_Usr") & "|^|" & Session("user") According to your code one variable holds the data of all users active at one time. Gonna try that. |
|
|||
Yes, that's right... one variable holds all the active users.
The |^| is used as the separator. When you want to use the variable (ie. output the active users), all you have to do is split the variable with |^|. Once split, you can manipulate the data to tell you how many members are online, who the members are, how many guests are online and the total number of users online. |
|
||||
Dude, that didnt work. Even for a single user testing, the variable wont show anything.
I have set the variable to store one data, thats the user's id. ANd when i tried to display it, it simply didnt show anything. Sub Session_OnStart Application.Lock Application("count") = application("count") + 1 count = Application("count") Application("Members")&count = Session("aka") Application.Unlock End Sub |
|
||||
The application count wasnt the problem actually, it is the Application("Members")&count = Session("aka"), which i could get to display. The apllication("count") was displayed as expected. i tested and found the session("eke") contained the data i wanted, so i assume the problem lies in the variable itself. Is it the wrong usage, or i was just mislead.
|
![]() |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Global Affiliate Network Come to Malaysia - Zanox.de AG | ZanoxCN | Revenue and Monetization | 8 | 04-02-2007 09:39 PM |
| Myspace Bulletin & Forum Signature Tracking | koolheaven | Other Webmaster-related Services and Promotion | 1 | 20-11-2006 05:33 PM |
| Myspace Bulletin & Forum Signature Tracking | iamlili | Other Webmaster-related Services and Promotion | 0 | 03-10-2006 05:36 AM |
| Village Girl, Global Business | paulhap | E-Commerce | 5 | 21-07-2004 01:49 PM |
| how many user using phpbb ? | jikey | Website Programming | 6 | 12-06-2004 02:00 AM |










Linear Mode

