Forums

This topic is locked

Users Online.

Posted 05 Jul 2002 04:04:07
1
has voted
05 Jul 2002 04:04:07 aegis kleais posted:
Ok, so how's it done? I'm assuming it's an Application Variable, with code like:

Application.Lock
Application("UsersOnline" = Application("UsersOnline" + 1
Application.Unlock

However this in it's most simplistic for works better as a page counter. Is this where you would use Session_onStart and Session_onEnd functions? What would a sample code be?

These OnStart and OnEnd......are they part of the Global.asa file?

Replies

Replied 06 Jul 2002 06:09:57
06 Jul 2002 06:09:57 aegis kleais replied:
BUMP!!! <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])
Replied 07 Jul 2002 00:17:04
07 Jul 2002 00:17:04 aegis kleais replied:
nevermind. figured it out myself. go forum power, go.

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])
Replied 07 Jul 2002 17:19:56
07 Jul 2002 17:19:56 Dave Clarke replied:
come on then tell us, i'm sure a lot of people would like to implement this feature<img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>
Replied 07 Jul 2002 18:15:48
07 Jul 2002 18:15:48 aegis kleais replied:
Ok.

Make a new Application in IIS and place global.asa in root. Global.asa should contain

&lt;script language="vbscript"&gt; runat="server"&gt;

sub application_onstart
application.lock
application("usersOnline" = 0
application("totalVisitors" = 0
application.unlock
end sub

sub session_onstart
application.lock
application("usersOnline" = application("usersOnline" + 1
application("totalVisitors" = application("totalVisitors" + 1
application.unlock
end sub

sub session_onend
application.lock
application("usersOnline" = application("usersOnline" - 1
application.unlock
end sub

&lt;/script&gt;
---------------------------------------------

When the server first starts the application (and these numbers'll be held til server shuts down/restarts) the variables are set to 0. Each time someone visits the website (whom supports Session cookies) usersOnline and totalVisitors is incremented. When sessions end, here's the deal:

If a session timeout is 20 minutes and a user leaves the website or logs out of session, the DECREMENT won't happen til.....20 minutes later; just because the user leaves the website doesn't mean the session expires, the timeout controls that. So what you want to do is say :

&lt;%
strPrintS = "s"
if Application("usersOnline" = 1 then strPrintS = ""
%&gt;
&lt;%= Application("usersOnline" %&gt; user&lt;%= strPrintS %&gt; are online. System updated every &lt;%= Session.Timeout %&gt; minutes.

-------------------------------------------------

This lets people know that the ACTUAL people online is only shown everytime a session expires or is terminated.

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])

Edited by - aegiskleais on 07 Jul 2002 18:16:25
Replied 07 Jul 2002 18:23:38
07 Jul 2002 18:23:38 Dave Clarke replied:
thanks <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

so with you saying make a new application in IIS, if i am running the site on another server, i presume that i would have to ask admin of that server to make the application and place my global.asa in the root for me?

Dave
Replied 07 Jul 2002 20:06:20
07 Jul 2002 20:06:20 aegis kleais replied:
Well, yes and no.

You do need to tell them to make you an application (applications start at YOUR directory's and apply to all folders below it) Tell them to ISOLATE the process (which they'll prolly do cause if the application fails, it doesn't take down the server with it; it'll just kill the application itself)

As for the global.asa, as long as you have FTP access, you can upload and modify it yourself.

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])
Replied 07 Jul 2002 21:26:38
07 Jul 2002 21:26:38 Dave Clarke replied:
thank you

i will try it here first with IIS

Dave
Replied 09 Jul 2002 16:21:41
09 Jul 2002 16:21:41 Dave Clarke replied:
hi

i think ive got this wrong but ..

didnt know how to make a new application in IIS so i just dropped the global.asa in my root and .. nothing.
took it out of my root and put it in the servers root ... success .. application variable shows up in data bindings panel and shows up on page .. but .. i dont for one minute imagine my server is going to give me access to their root!!!!
so how do i get it to work from my sites root?

Dave
Replied 09 Jul 2002 20:50:36
09 Jul 2002 20:50:36 Dave Thomas replied:
Could be wrong here, but, if you place the global.asa in the root of your online directory then surely it will act as your local root(server), because an IP on most hosting servers now is classed as a virtual server anyway, and will probably give you the permissions you need.
This is a thought not a fact. (I'll find out on my servers behalfs for future reference)

"Get the kettle on, time for a brew"
Replied 09 Jul 2002 22:26:33
09 Jul 2002 22:26:33 aegis kleais replied:
Using IIS 5, open the ISM

Expand the left panel til you find your website's root directory (not the server root). Right click &gt; PROPERTIES.

On DIRECTORY tab, look at bottom. Press CREATE button for Application and change the app protection to HIGH (Isolated) Then place Global.asa in YOUR root.

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])
Replied 10 Jul 2002 17:56:01
10 Jul 2002 17:56:01 Dave Clarke replied:
thanks aegiskleais

done that now and appears to be working fine

<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

while we are on the subject of IIS how do i change the session timeout? and does this only affect inactivity?, what i mean is if i set it to ten mins does it timeout after 10 mins of inactivity or ten mins no matter what?

thanks

Dave

Edited by - Davecl on 10 Jul 2002 19:47:46
Replied 10 Jul 2002 17:59:59
10 Jul 2002 17:59:59 Dave Clarke replied:
you might be right UltraDav, but i tried it on IIS here at home and no luck, maybe works online with a "proper" server, i'll bung it on yours and see
<img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>

Dave

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Could be wrong here, but, if you place the global.asa in the root of your online directory then surely it will act as your local root(server), because an IP on most hosting servers now is classed as a virtual server anyway, and will probably give you the permissions you need.
This is a thought not a fact. (I'll find out on my servers behalfs for future reference)

"Get the kettle on, time for a brew"
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 10 Jul 2002 18:05:27
10 Jul 2002 18:05:27 Dave Clarke replied:
well ultradav
looks like you were right, stuck the global.asa in my site directory on your server and hey presto up pops the number of users online.

Dave

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
you might be right UltraDav, but i tried it on IIS here at home and no luck, maybe works online with a "proper" server, i'll bung it on yours and see
<img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>

Dave

[<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 10 Jul 2002 20:24:25
10 Jul 2002 20:24:25 aegis kleais replied:
Dave, Session Timeouts can be controlled with

Session.Timeout = X

where X = number of minutes long you want the session to be.

Some servers have load balancing that will override your session timeout in order to keep resources open on the server. What I recommend doing is creating a system where a page refreshes itself every 5 minutes. This way it jerry-rigs to keep the server alive by making valid GET requests.

Once a page is called, a timer begins. If no action is performed on the server in the timeout period, the session is dropped. Not X minutes total time...

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])
Replied 10 Jul 2002 21:16:05
10 Jul 2002 21:16:05 Dave Clarke replied:
thanks aegiskleais

the reason i was asking is because IIS won't let me open pages, keeps telling me that there are too many users even though there are no pages open, i assume it is keeping the session alive after i have closed my browser, there fore it thinks im still in a session.

Dave
Replied 10 Jul 2002 21:36:50
10 Jul 2002 21:36:50 Dave Clarke replied:
another thought .. could it be the global.asa or something .. the application lock .. keping the session open?
Replied 10 Jul 2002 21:45:54
10 Jul 2002 21:45:54 aegis kleais replied:
You know, I have the same problem. Open 3-5 session on IIS and it says TOO MANY USERS CONNECTED. Just restart your computer and start devising methods that set Session.Timeout = 1 before it abandons the session (sessions live on even when abandoned until the Timeout)

At first I thought people were ACCESSING my computer! But then I checked the SQL Activity logs, to find out that it was multiple instances of my computer..... I still havn't found a method of adjusting this on a WinXP platform

btw, Application.Lock just prevents others from altering Application Variables while you make modifications; doesn't do anything to the session

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])

Edited by - aegiskleais on 10 Jul 2002 21:46:40
Replied 11 Jul 2002 13:26:35
11 Jul 2002 13:26:35 David Behan replied:
I use a script that I found on aspin.com for this. It is in two parts. The first is in my functions.asp page and is included at the top of each page after the config.asp include file. It contains:

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>&lt;%
'======================================
'RECORDS THE ACTIVE USER IN APPLICATION
'VARIABLE AND UPDATES TIMESTAMP
'======================================

Sub LogActiveUser
Dim strActiveUserList
Dim intUserStart, intUserEnd
Dim strUser
Dim strDate

strActiveUserList = Application("ActiveUserList"

If Instr(1, strActiveUserList, Session.SessionID) &gt; 0 Then
Application.Lock
intUserStart = Instr(1, strActiveUserList, Session.SessionID)
intUserEnd = Instr(intUserStart, strActiveUserList, "|"
strUser = Mid(strActiveUserList, intUserStart, intUserEnd - intUserStart)
strActiveUserList = Replace(strActiveUserList, strUser, Session.SessionID & ":" & Now())
Application("ActiveUserList" = strActiveUserList
Application.UnLock
Else
Application.Lock
Application("ActiveUsers" = CInt(Application("ActiveUsers") + 1
Application("ActiveUserList" = Application("ActiveUserList" & Session.SessionID & ":" & Now() & "|"
Application.UnLock
End If
End Sub

'======================================
'END SCRIPT | END SCRIPT | END SCRIPT
'======================================

'======================================
'CLEANS UP THE APPLICATION VARIABLES TO
'CORRECTLY RECORD CURRENT USERS ON SITE
'======================================

Sub ActiveUserCleanup
Dim ix
Dim intUsers
Dim strActiveUserList
Dim aActiveUsers
Dim intActiveUserCleanupTime
Dim intActiveUserTimeout

intActiveUserCleanupTime = 1 'In minutes, how often should the ActiveUserList be cleaned up.
intActiveUserTimeout = 5 'In minutes, how long before a User is considered Inactive and is deleted from ActiveUserList

If Application("ActiveUserList" = "" Then Exit Sub

If DateDiff("n", Application("ActiveUsersLastCleanup", Now()) &gt; intActiveUserCleanupTime Then

Application.Lock
Application("ActiveUsersLastCleanup" = Now()
Application.Unlock

intUsers = 0
strActiveUserList = Application("ActiveUserList"
strActiveUserList = Left(strActiveUserList, Len(strActiveUserList) - 1)

aActiveUsers = Split(strActiveUserList, "|"

For ix = 0 To UBound(aActiveUsers)
If DateDiff("n", Mid(aActiveUsers(ix), Instr(1, aActiveUsers(ix), ":" + 1, Len(aActiveUsers(ix))), Now()) &gt; intActiveUserTimeout Then
aActiveUsers(ix) = "XXXX"
Else
intUsers = intUsers + 1
End If
Next

strActiveUserList = Join(aActiveUsers, "|" & "|"
strActiveUserList = Replace(strActiveUserList, "XXXX|", ""

Application.Lock
Application("ActiveUserList" = strActiveUserList
Application("ActiveUsers" = intUsers
Application.UnLock

End If

End Sub

'======================================
'END SCRIPT | END SCRIPT | END SCRIPT
'======================================


%&gt;
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Then I just call it where ever I want on the page using:

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
&lt;%
Call LogActiveUser()
Call ActiveUserCleanup()
Response.Write "ActivUsers: " & Application("ActiveUsers"
%&gt;
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

It works fine for me. Regards,


Dave



_________________________
David Behan - www.site-manager.com/af.asp?a=11&l=1tds9p6x2
Replied 11 Jul 2002 16:05:31
11 Jul 2002 16:05:31 Dave Clarke replied:
thanks yet again aegiskleais

i wouldnt think this will be a problem on a proper server, just testing on IIS so i wont rack my brains too much trying to set Session.Timeout=1

Dave
Replied 11 Jul 2002 16:10:09
11 Jul 2002 16:10:09 Dave Clarke replied:
so beano, i would create a page - functions.asp and then put <b>&lt;!--#include file="functions.asp" --&gt;</b> on every page and then just call the application variable when needed?

Dave
Replied 11 Jul 2002 16:13:22
11 Jul 2002 16:13:22 David Behan replied:
That's what I did and it worked grand. Tell me how you got on.

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
so beano, i would create a page - functions.asp and then put <b>&lt;!--#include file="functions.asp" --&gt;</b> on every page and then just call the application variable when needed?

Dave
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

_________________________
David Behan - www.site-manager.com/af.asp?a=11&l=1tds9p6x2
Replied 11 Jul 2002 17:44:41
11 Jul 2002 17:44:41 Dave Clarke replied:
hi beano

tried it and get this error message

Technical Information (for support personnel)

Error Type:
Microsoft JScript compilation (0x800A03F7)
Unterminated string constant
/newreunite/functions.asp, line 2, column 39

copied and pated your code to new page

&lt;%
'======================================<font color=red>line 2</font id=red>
'RECORDS THE ACTIVE USER IN APPLICATION
'VARIABLE AND UPDATES TIMESTAMP
'======================================

it's only a comment line so cant understand it.
any ideas??

Dave
Replied 12 Jul 2002 20:15:12
12 Jul 2002 20:15:12 scre wdanger replied:
Hi,
I don't understand why taking so much pain when there is an extension available, i think "ASP dream" it just writes the required code in the Global.asa file. All you have to is to put this file in the Site root folder.
Much more interresting would be to find out a proper code so that the name of the users online could be shown.
Replied 12 Jul 2002 20:28:21
12 Jul 2002 20:28:21 aegis kleais replied:
The point for me is not to have extensions do everything for me. I want to LEARN ASP. Just getting extensions limit you to the way that developer does things and you don't learn a thing

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])
Replied 13 Jul 2002 05:04:40
13 Jul 2002 05:04:40 scre wdanger replied:
Great luv it,
Still using extension doesn't mean that you shouldn't learn things, its upto you. I use extensions coz they are time saving.

Regards<img src=../images/dmxzone/forum/icon_smile_dissapprove.gif border=0 align=middle>

Reply to this topic