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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing User Session(IP Counter) info. not working well???

Status
Not open for further replies.

AnnYH

IS-IT--Management
Jul 22, 2002
22
0
0
CA
Hi, Everyone:

I have two problems:

1.Counter:
My counter doesn’t work properly. Some time it can count in, some times not.

Code in global.asa

Sub InCrementCounter()

Set fsc=Server.CreateObject("Scripting.FileSystemObject")
Set txt=fsc.OpenTextFile(Server.MapPath("AcsCounter.txt"),1)
Application("Counter")=txt.ReadLine
txt.close

Application("Counter")=Application("Counter")+1

Set txt=fsc.CreateTextFile(Server.MapPath("AcsCounter.txt"),1)

txt.Write(Application("Counter"))
txt.Close

End Sub

Sub Application_OnStart
On Error Resume Next

''//
Application.Lock

InCrementCounter

Application.Unlock

''//
End Sub

2.Capturing User Session IP Address: I used Request.ServerVariables("Romete_ADDR"), but I got nothing. No any IP or URL show up.

Code:
Sub Session_OnStart
On Error Resume Next

strSLog="Insert Into tblWebSession "_
& (EventType,UserURL,Referer,HITIP,RemoteHost,UserAgent,UserSID,HostIP)"_
& "Values('New Session','"_
& Request.ServerVariables("URL") & "','"_
& Request.ServerVariables("HTTP_REFERER") & "','"_
& Request.ServerVariables("Romete_ADDR") & "','"_
& Request.ServerVariables("Romete_Host") & "','"_
& Request.ServerVariables("HTTP_User_Agent") & "',"_
& CLng(Session.SessionID) & ",'"_
& Request.ServerVariables("LOCAL_Addr") & "')"


WriteSessionData(strSLog)

End Sub

Where I did wrong?
By the way, our web server is NT, is that cause the problem?

Thanks advance.
Ann
 
You forgot to place your Counter incrementing in Session_OnLoad event. in Application_OnLoad event gives you the ability to read the user count from a file.
Try to get this line off
On Error Resume Next
This way you wont knw who caused the error.


Sub InCrementCounter
Set fsc=Server.CreateObject("Scripting.FileSystemObject")
Application("Counter")=Application("Counter")+1
Set txt=fsc.CreateTextFile(Server.MapPath("AcsCounter.txt"),1)
txt.Write(Application("Counter"))
txt.Close
End Sub

Sub SaveCounter
Set fsc=Server.CreateObject("Scripting.FileSystemObject")
Set txt=fsc.CreateTextFile(Server.MapPath("AcsCounter.txt"),1)
txt.Write(Application("Counter"))
txt.Close
End Sub

Sub LoadCounter
Set fsc=Server.CreateObject("Scripting.FileSystemObject")
Set txt=fsc.OpenTextFile(Server.MapPath("AcsCounter.txt"),1)
Application("Counter")=txt.ReadLine
txt.close
End Sub

Sub Application_OnStart
Application.Lock
LoadCounter
Application.Unlock
End Sub

Sub Application_OnEnd
Application.Lock
SaveCounter
Application.Unlock
End Sub

Sub Session_OnStart
InCrementCounter
'your code here
End Sub

________
George, M
 
Thanks, George. You are great. It's fixed.
Do you know about my second problem? :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top