Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Current IP addresses viewing website.

Maybe using a Global.asa script...

6:35 pm on Oct 7, 2005 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2005
votes: 0

I am wondering if there is a way to generate a list of IP addresses currently viewing the website instead of a # of connections. Here is the code I am currently using to view how many people are viewing the site:


Sub Application_OnStart
' Set our user count to 0 when we start the server
Application("ActiveUsers") = 0
End Sub

Sub Session_OnStart
' Change Session Timeout to 20 minutes (if you need to)
Session.Timeout = 5
' Set a Session Start Time
' This is only important to assure we start a session
Session("Start") = Now
' Increase the active visitors count when we start the session
Application("ActiveUsers") = Application("ActiveUsers") + 1
End Sub

Sub Session_OnEnd
' Decrease the active visitors count when the session ends.
Application("ActiveUsers") = Application("ActiveUsers") - 1
End Sub


Any comments or suggestions would greatly be appreciated.


3:03 am on Oct 10, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 6, 2004
votes: 0

I'm no guru but:
Dim ClientIP As String = [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpRequestClassUserHostAddressTopic.asp]Request.UserHostAddress[/url]

is used in an application I've inherited.

This is used in the application that is being run by the user. I guess you could log this with a date and time and then analyse later.

3:17 am on Oct 10, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
votes: 0

I have the very thing:

<object runat="Server" scope="Application"
id="rstActiveUsers" progid="ADODB.Recordset">

<script language="VBScript" runat="Server">
' The first thing you should notice is the top line.
' It creates an application scoped recordset object
' named rstActiveUsers that I'll use to store all
' our user information.
' Note: I've wrapped it for readability

Sub Application_OnStart()
' Selected constants from adovbs.inc
Const adInteger = 3
Const adVarChar = 200
Const adDate = 7

' Here I set up in memory active user recordset
' by adding the fields I want to it and defining
' their data types.
rstActiveUsers.Fields.Append "id", adInteger
rstActiveUsers.Fields.Append "ip", adVarChar, 15
rstActiveUsers.Fields.Append "browser", adVarChar, 255
rstActiveUsers.Fields.Append "started", adDate

' Next I open our recordset so that we can use it.
' That basically gets everything ready for our
' first user.
End Sub

Sub Session_OnStart()
' Set session timeout to 20 minutes
Session.Timeout = 20

' Set a session start time. This is pretty pointless,
' but it does ensure that we start a session and
' assign the user a session id and it can help
' troubleshooting if we ever need it.
Session("Start") = Now()

' Move to the end so records are added in order.
' Again not of any real importance, but it keeps our
' user table nice and orderly.
If Not rstActiveUsers.EOF Then rstActiveUsers.MoveLast

' Add a record and insert users data. I'm just
' storing some basic info, but naturally you're free
' to store whatever you want.

rstActiveUsers.Fields("id").Value = _

rstActiveUsers.Fields("ip").Value = _

rstActiveUsers.Fields("browser").Value = _

rstActiveUsers.Fields("started").Value = _


' Now that we've got the information, all that's
' left is to display it. See test_page.asp for a
' demo. It includes the pages show_count.asp and
' show_users.asp which can also be used
' individually if desired.
End Sub

Sub Session_OnEnd()
' Selected constants from adovbs.inc
Const adAffectCurrent = 1

' Start at the first record

' Check each record for the SessionID
Do While Not rstActiveUsers.EOF
' Do conversion to Long to be sure we're
' comparing the same data type.
If CLng(rstActiveUsers.Fields("id").Value) = _
CLng(Session.SessionID) Then
rstActiveUsers.Delete adAffectCurrent
End If


End Sub

Sub Application_OnEnd()
' Not like it really matters, but for the sake of
' good coding practice I close the recordset when
' our application is shutting down.
End Sub

this creates a recordset with a list of all the active sessions by IP address.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members