View Full Version : Naming IP Addresses, current users online, etc.

09-25-2005, 11:33 PM
What I am trying to accomplish is creating a script that allows users to add their "name" to their IP address so when there is for example 5 viewers online the script will show names of those IP address who have supplied names, and just display the IP address of those who havn't. Here is the global script I am currently using to display how many visitors are currently online. I am wondering if there is a way to display what IP ADDRESSES are connected to the server. If someone could help me with getting the list of IP addresses that are currently connected instead of just a number # I can come up with the rest of the script. Thanks for your time. I'll post with any luck I have.


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


<%= Application("ActiveUsers") %>

09-27-2005, 02:07 AM
Perhaps I should break it down a little. Basically I am wondering if it's possible to see what IP addresses are viewing a website, perhaps using the Global.asp script. The script gives me a # of current viewers, why not their IP address. Thanks for your time.

09-27-2005, 11:47 PM
Awhile back I wanted to list the names of all the users at my site that had logged in. I had already used a global script very much like your were it would display how many visitors were at my site. So I wrote a script that would add the names of the users to the Application(UserName). I would add a comma at the end of each name so that when I displayed the list I would just replace the commas with a <br> and it worked great. That is until a user left the site, there is or should I say it is very hard to delete just one name and it being the right name out of Application(UserName). So I posted for help here on this board, the response was to use a dictionary. I did a little research on dictionary and found that I really had three choices, dictionary, database, text file. To try to use the global application is not the right way to do this.

What I ended up doing was putting a timestamp field in my database so when someone logged in I would read the database by the timestamp and that would give me the list of current logged in users. I could display this anywhere on the site for anyone to see if I wanted to. But this didnít help me with the visitors that were at my site that had not logged in. Sometimes I can see that there are 15 users online with 5 names displayed for the ones that are logged in. But I have nothing to see for these other 10 users that were there.

What I am planning on doing is when they first load my page, and on Session_OnStart I am going to write their IP to a text file. This way I can display the text file anywhere I want for anyone that I want to see. But I donít think it a good idea to display users IP to anyone. Then on Session_OnEnd I will delete their IP from the text file. What I should end up with is 5 names of logged in users and a list of 10 IP address. I know that after someone logs in I will have to delete their IP out of the text file so that I don't show the IPs of logged in users also.

But by trade I am in air-conditioning I code because its fun and I love it. But with this hot summer we have been having this year I havenít had the time to write the first line code to make this happen.

Sorry I donít have any code for you to see but I am hoping that this will give you some ideas on solving your problem. Global applications are great for something but I really don't think that this is one of them. So your choices are dictionary, database, text file.

09-28-2005, 12:00 AM
I appreciate the long responce. I am planning on using textfiles, however I'm not sure how I would go about adding an IP addess to the textfile when a session starts and then removing it when that session ends... Any ideas on that one?

What I am hoping for is a textfiles with 10 IP addresses when there are 10 people viewing the site. What I will then do is replace the IP addresses with the supplied names, or write "No Name" for the IP addresses that don't have a name. I'll use the ASP REPLACE command as well as other script for this.

I think I could get this to work baced on two things:

#1 I need to figure out how to APPEND the viwers IP address to a textfile when THEIR session starts.
#2 I need to figure out how to remove THEIR IP address from that textfile when THEIR session ends, but leave everyone elses.

Thanks for your time and ideas...