Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 17-12-2003, 08:29 PM
syahrezan's Avatar
Novice Webmaster
 
Join Date: Feb 2002
Location: Kuala Lumpur
Posts: 39
Rep Power: 0
syahrezan is on a distinguished road
Send a message via Yahoo to syahrezan
Global asa and user tracking

Dudes, this global asa thingy, can i just write what ever code as if im writing a normal asp page? Because im trying to have this 'currently active user' list. I was advised to incorporate database insertion, which i tried but doesnt seem to work. The way i did was i wrote some codes in the application on start to get the users login time and tried to retrieve it to list all the active users. but that didnt work. Could somebody help me put here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 18-12-2003, 03:02 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
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
To use the script use the following code:

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 %>
Members (with user name) Online:
Code:
<% If UBound(v_user) = -1 Then %>0<% Else Response.Write UBound(v_user) End If %>
Guests online
Code:
<% If UBound(v_guest) = -1 Then %>0<% Else Response.Write UBound(v_guest) End If %>
To use the members function, you will need the login code (and some other bits of code). It’s about 15000-20000 lines of code and I don’t really remember what each variable/fuction/subroutine does. But if you like to have a look and want the full code, PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 18-12-2003, 03:07 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
BTW, application on start doesn't work with normal ASP file, it only works with ASA files.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 18-12-2003, 09:25 PM
syahrezan's Avatar
Novice Webmaster
 
Join Date: Feb 2002
Location: Kuala Lumpur
Posts: 39
Rep Power: 0
syahrezan is on a distinguished road
Send a message via Yahoo to syahrezan
Thats a lot of codes, but thanks, ill try that one out. But still, for curiosity's sake, how could i do it with global.asa? And yes, the applicationonstart is in the global.asa.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 19-12-2003, 08:41 AM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
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>
To use the code, just include the following line in the ASP file where you would like to display your active users.

Some.asp
Code:
<% Response.Write Application("Sessions") %>
The difference between this code and the earlier one, is
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 24-12-2003, 10:31 PM
syahrezan's Avatar
Novice Webmaster
 
Join Date: Feb 2002
Location: Kuala Lumpur
Posts: 39
Rep Power: 0
syahrezan is on a distinguished road
Send a message via Yahoo to syahrezan
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 24-12-2003, 11:21 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
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
When a member logs in, they should be assigned a session named 'user'.

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 24-12-2003, 11:23 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
Quote:
I would like to get this clear : are variables declared in global.asa can be recognized in your normal asp page?
Yes, if you declare it in global.asa, it will be available for use in all your asp pages.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 26-12-2003, 09:45 PM
syahrezan's Avatar
Novice Webmaster
 
Join Date: Feb 2002
Location: Kuala Lumpur
Posts: 39
Rep Power: 0
syahrezan is on a distinguished road
Send a message via Yahoo to syahrezan
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 27-12-2003, 11:47 AM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 27-12-2003, 08:19 PM
syahrezan's Avatar
Novice Webmaster
 
Join Date: Feb 2002
Location: Kuala Lumpur
Posts: 39
Rep Power: 0
syahrezan is on a distinguished road
Send a message via Yahoo to syahrezan
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 27-12-2003, 09:00 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 01-01-2004, 12:50 PM
syahrezan's Avatar
Novice Webmaster
 
Join Date: Feb 2002
Location: Kuala Lumpur
Posts: 39
Rep Power: 0
syahrezan is on a distinguished road
Send a message via Yahoo to syahrezan
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 02-01-2004, 09:18 PM
Senior Webmaster
 
Join Date: Oct 2001
Location: Melbourne, AU
Posts: 456
Rep Power: 97
sufyan is on a distinguished road
Hi,

haven't tested the code myself, but im assuming that you were using:

Response.Write count

If so, try using:

Response.Write Application("count")

See if that works.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 02-01-2004, 10:43 PM
syahrezan's Avatar
Novice Webmaster
 
Join Date: Feb 2002
Location: Kuala Lumpur
Posts: 39
Rep Power: 0
syahrezan is on a distinguished road
Send a message via Yahoo to syahrezan
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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