Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PLEASE HELP...global.asa problem still exists

Status
Not open for further replies.

motte

Programmer
May 31, 2001
155
US
I have a problem with my global.asa. I posted earlier this week and had only one response, but it wasn't what I was looking for (though I do thank TimFerris for lending me his time). Please have a look anyone and see if you can find what is wrong.

I want to see how many sessions are currently open, and at the same time, find each remote ip address. I can get the number of sessions at any one time, but when I loop thru my array (which is actually an application variable), I can only see the latest ip address but the correct num of sessions. The other ip addresses are blank. Can you please take a look at my code? Any suggestions would be helpful.
***********************************************************
global.asa below
************************************************************
<script language=&quot;vbscript&quot; runat=&quot;server&quot;>
sub Application_OnStart
application(&quot;USERS&quot;)=0
dim urls(0)

application(&quot;URLS&quot;)=urls
end sub

sub session_onstart
session.timeout=1
session(&quot;Start&quot;)=now

application.lock
application(&quot;USERS&quot;) = application(&quot;USERS&quot;) + 1
size=application(&quot;USERS&quot;)
redim preserve urls(size-1)

application.unlock

application.lock
urls(size-1)=request.servervariables(&quot;REMOTE_ADDR&quot;)
application(&quot;URLS&quot;)=urls
application.unlock
end sub

sub session_onend
application.lock
application(&quot;USERS&quot;)=application(&quot;USERS&quot;) - 1
application.unlock

redim urls(size-1)
session(&quot;URL&quot;)=request.servervariables(&quot;REMOTE_ADDR&quot;)
urls(size-1)=session(&quot;URL&quot;)
application(&quot;URLS&quot;)=urls
end sub
</script>
************************************************************
page displaying sessions/ip addresses below
************************************************************
<!-- #include virtual=&quot;/global.asa&quot; -->
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY>
<%
response.write (&quot;This many sessions are open: &quot; & application(&quot;USERS&quot;) & &quot;<br>&quot;)

dim counter
for counter=0 to ubound(application(&quot;URLS&quot;))
response.write counter & &quot;: &quot; & application(&quot;URLS&quot;)(counter) & &quot;<br>&quot;
next
%>

</BODY>
</HTML>
************************************************************

Hopefully you can figure out my mess.

Mike
 
I think this solve your problem...

Code:
<script language=&quot;vbscript&quot; runat=&quot;server&quot;>
sub Application_OnStart
    application(&quot;USERS&quot;)=0
    dim urls()
    
    application(&quot;URLS&quot;)=urls
end sub

sub session_onstart
    session.timeout=1
    session(&quot;Start&quot;)=now
    
    application.lock
    application(&quot;USERS&quot;) = application(&quot;USERS&quot;) + 1
    size=application(&quot;USERS&quot;)
    redim preserve urls(size)
    
    application.unlock

    application.lock
    urls(size)=request.servervariables(&quot;REMOTE_ADDR&quot;)
    application(&quot;URLS&quot;)=urls
    application.unlock
end sub

sub session_onend
    application.lock
    application(&quot;USERS&quot;)=application(&quot;USERS&quot;) - 1
    application.unlock
    'this is the line missing
    size=application(&quot;USERS&quot;)

    redim urls(size)    
    session(&quot;URL&quot;)=request.servervariables(&quot;REMOTE_ADDR&quot;)
    urls(size)=session(&quot;URL&quot;)
    application(&quot;URLS&quot;)=urls
end sub
</script>

i hope this works cuz i dont have to mutch time to see it...
but if u need help please tell me. ________
George, M
 
shaddow,

actually it doesn't work. The #users increments and the ip address gets added in but the older users ip addresses get flushed out. Its exactly what mine does. I'm currently trying a different way with a temporary array. It works but I don't know if I like it. Here is the code for you to view. If anyone else has any suggestions, please let me know.

Mike

***********************************************************
<script language=&quot;vbscript&quot; runat=&quot;server&quot;>
'dim urls(1)
sub Application_OnStart
application(&quot;USERS&quot;) = 0

dim urls(0)
urls(0)=&quot;none&quot;
application(&quot;URLS&quot;)=urls
application(&quot;STRING&quot;) = &quot;&quot;

end sub

sub session_onstart
session.timeout=1
session(&quot;Start&quot;) = now

dim tempar()
dim cnt

for cnt=0 to ubound(application(&quot;URLS&quot;))
next

redim preserve tempar(ubound(application(&quot;URLS&quot;)))

dim el, x
x=0
for each el in application(&quot;URLS&quot;)
tempar(x) = el
x=x+1
next

application.lock
application(&quot;USERS&quot;) = application(&quot;USERS&quot;) + 1
application.unlock

size = application(&quot;USERS&quot;)

redim preserve urls(size - 1)

dim count
for count=0 to ubound(tempar)
urls(count)=tempar(count)
next

'application.lock
'
'application.unlock

urls(size - 1) = request.servervariables(&quot;REMOTE_ADDR&quot;)
dim string1
string1=join(urls, &quot;:&quot;)

application.lock
application(&quot;STRING&quot;) = string1
application(&quot;URLS&quot;) = urls
application.unlock

end sub

sub session_onend

application.lock
application(&quot;USERS&quot;) = application(&quot;USERS&quot;) - 1
application(&quot;IP&quot;) = session(&quot;OPENSES&quot;)
application.unlock
'
application.lock
dim size
size = application(&quot;USERS&quot;)
redim preserve urls(size - 1)
session(&quot;URL&quot;) = request.servervariables(&quot;REMOTE_ADDR&quot;)
urls(size - 1) = session(&quot;URL&quot;)
application(&quot;URLS&quot;) = urls
application.lock
end sub
</script>
 
Try Diming the urls array in the Session Subs and assigning the Application variable to it, then working with the array and reassign it to the Application variable. Or you could just work directly with the Application variable as you do on the printout page.

Also your whole Session_onend won't work right because you are attempting to just remove the last entry in the array but you don'y really know who left. &quot;A computer scientist is a person who knows when it is time to hit the computer.&quot;

John

johnmc@mvmills.com
 
Thanks for your concern, but i try to modify your code to work.
I have another way to deal with it and works just fine and simple.
Or u could try to dim and redim Application(&quot;URLS&quot;) like jmcpher says.

But if u dont find a solution i will share mine... witch i currently use. ________
George, M
 
shaddow,

i'd like to see yours if you don't mind. I can get them in now, but I can't get them to exit the application variable. Email me at motte@fastweb.com. I appreciate the time you spent.

Mike
 
I use Application.Contents to store my variables.
Key is the name of the variable in the Contents object
and Application.Contents(key) is the value.
Is like u declare for each user an Application(&quot;varname&quot;)=value and then u are finished u remove the key from the collection
Hope this Helps U
Here is my example of
global.asa

Code:
<script language=&quot;vbscript&quot; runat=&quot;server&quot;>
sub Application_OnStart
    Application(&quot;users&quot;)=0
end sub
set d=Server.CreateObject(&quot;Scripting.Dictionary&quot;)
sub Session_OnStart
    Application.lock
    Application(&quot;users&quot;) = Application(&quot;users&quot;) + 1
    key=Application(&quot;users&quot;)
    Application(key)=Request.ServerVariables(&quot;REMOTE_ADDR&quot;).Item
    Application.unlock
end sub

sub session_onend
    Application.lock
    key=Application(&quot;users&quot;)
    Application.Contents.Remove(key)
    Application(&quot;users&quot;)=Application(&quot;users&quot;) - 1
    Application.unlock
end sub
</script>


And test.asp

Code:
<HTML>
<BODY>
<% 
response.write (&quot;This many sessions are open: &quot; & application(&quot;USERS&quot;) & &quot;<br>&quot;)
for each url in Application.Contents
	response.write  url& &quot;: &quot; &Application.Contents(url)& &quot;<br>&quot;
next
%>
</BODY>
</HTML>

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top