Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 15th, 2003, 06:46 AM
Registered User
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Dr Robert James Send a message via AIM to Dr Robert James Send a message via MSN to Dr Robert James Send a message via Yahoo to Dr Robert James
Default Global.asa Help Pl

Hello Friends,
I need some here pl. Below is my global.asa file
which keeps track of no of active visitors and
routine logging to a .txt file.

I need to call ONLY active visitors with their ip's
and date and time, thro a diff .asp file eg ip.asp

Pl help, i need it for my website.
Thanks

James
Email: [email protected]
.........................
Global.asa file content.


<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>
on error resume next
dim date_stamp
date_stamp=Now()
dim fs,f
dim tst
tst=server.mappath("/testread.txt")
set fs=Server.CreateObject("Scripting.FileSystemObject ")
set f=fs.OpenTextFile(Server.MapPath("/testread.txt"),8,true)
f.WriteLine("Vistor visted u r site" & chr(32)& request.servervariables("REMOTE_ADDR") & chr(32) & "ON" & chr(32) & date_stamp)
f.Close
set f=Nothing
set fs=Nothing
'Response.Write "Cool!!"

Sub Application_OnStart
Application("Active")=0
End Sub

Sub Application_OnEnd
'no code is needed here
End Sub

Sub Session_OnStart
Session.Timeout=5
Session("Start")=Now
Application.Lock
Application("Active")=Application("Active")+1
'this adds 1 to the number of active users when a new user hits
Application.unlock
End Sub

Sub Session_OnEnd
Application.Lock
Application("Active")=Application("Active")-1
'this subtracts 1 from the number of active users when a new user leaves
Application.unlock
End Sub

</SCRIPT>

Robert James
MD (Internal Medicine)
Ph:919814118442
Email:
[email protected]
 
Old August 15th, 2003, 07:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to have all of your code in a subroutine when using Global.asa. Try using the following code:

Code:
<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>
Sub Application_OnStart
    Application("Active") = 0
End Sub

Sub Session_OnStart

Dim date_stamp, fs, f, tst

    On Error Resume Next

    date_stamp = Now()
    tst = Server.MapPath("/testread.txt")
    Set fs = Server.CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile(tst), 8, True)
    f.WriteLine("Vistor visted u r site " & _
        Request.ServerVariables("REMOTE_ADDR") & " ON " & date_stamp)
    f.Close
    Set f = Nothing
    Set fs = Nothing

    Session.Timeout = 5
    Session("Start") = date_stamp
    Application.Lock
    Application("Active")=Application("Active")+1
    'this adds 1 to the number of active users when a new user hits
    Application.unlock

End Sub 

Sub Session_OnEnd

    Application.Lock
    Application("Active") = Application("Active") -1
    'this subtracts 1 from the number of active users when a new user leaves
    Application.unlock

End Sub 
</SCRIPT>
Firstly I have moved the code at the top of your code listing that was not in a subroutine into the Session_OnStart subroutine. Also you declare a variable tst and set it to a mapped path, however you do not use it in your code. Instead of having:

Code:
Set f = fs.OpenTextFile(Server.MapPath("/testread.txt"), 8, true)
You can use:

Code:
Set f = fs.OpenTextFile(tst), 8, True)
Instead of using character 32's (Chr(32) - space) you can just insert the spaces into your strings. This line:

Code:
f.WriteLine("Vistor visted u r site " & _
    Request.ServerVariables("REMOTE_ADDR") & " ON " & date_stamp)
    Is a lot easier to read than this line:

Code:
f.WriteLine("Vistor visted u r site" & Chr(32) & _
    Request.ServerVariables("REMOTE_ADDR") & Chr(32) & "ON" & _
    Chr(32) & date_stamp)
    I hope I have made sense and been able to help.

Regards
Owain Williams
 
Old August 16th, 2003, 05:51 PM
Registered User
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Dr Robert James Send a message via AIM to Dr Robert James Send a message via MSN to Dr Robert James Send a message via Yahoo to Dr Robert James
Default

Hello N Thanks Williams
I tried ur code, it showed error line 15
...........................
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/desk/global.asa, line 15, column 28
Set f = fs.OpenTextFile(tst),8, True)
..................................

could u pl make a global.asa file and email me? It would be a
lot easier.
I want to be able to see the current active visitors on my
iis server along with their ip and date n time they visited.
Need the file badly sir... if u could email it to me,
shall be grateful.
Regards



Robert James
MD (Internal Medicine)
Ph:919814118442
Email:
[email protected]
 
Old August 18th, 2003, 03:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Dr Robert James
 Hello N Thanks Williams
I tried ur code, it showed error line 15
...........................
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/desk/global.asa, line 15, column 28
Set f = fs.OpenTextFile(tst),8, True)
one opening ( and two closing ) so its obviously just a typo. Change it to
Set f = fs.OpenTextFile(tst,8, True)
 
Old September 6th, 2003, 10:23 PM
Registered User
 
Join Date: Sep 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricefarmer
Default

Now now. Give him a break. He is a brave MD who is writing code.

But then again, if he is a surgeon, he should grasp the concept of one opening, one closing :D

 
Old October 4th, 2003, 02:56 AM
Registered User
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Dr Robert James Send a message via AIM to Dr Robert James Send a message via MSN to Dr Robert James Send a message via Yahoo to Dr Robert James
Default

Thanks Rice :)
I am a Physician, n not a surgeon. :)
I still could not get help on how to write a code in
global.asa , so that i should be able to see no of total
visitors at my iis server at one particular time,
along with ip and date n time displayed.
.......................................
Shall be great if some one can help me with this.
.......................................

Robert James
MD (Internal Medicine)
Ph:919814118442
Email:
[email protected]
 
Old October 6th, 2003, 02:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Robert,

At the moment you have some code to increment and decrement an application variable. This variable stores the total number of active users (ie, it's a counter). This works because when a user's session starts, or ends, events are fired (session_OnStart, and session_OnEnd), and you can have some code in your global.asa that runs when those events are fired.

However, if you want to store IP addresses, you need to store a list someplace. This could be in a database, or in some kind of hashtable or array that you store in the server's memory.

Again, you need to have code that runs during Session_OnStart and Session_OnEnd to add/delete the appropriate records from your list.

Cheers
Ken

Microsoft MVP - Windows Server (IIS)
www.adOpenStatic.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
About Global.asa pbcatan Classic ASP Databases 2 December 4th, 2006 12:40 AM
global.asa vin_0x1 Classic ASP Components 2 July 24th, 2006 01:13 AM
GLOBAL.ASA zaeem Classic ASP Databases 3 November 4th, 2003 09:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.