PDA

View Full Version : Online users?


Speedy
10-18-2005, 07:51 PM
Hello ppl!

I'm trying to make a script that output who's online at the moment on a page like in an community page, but I don't know which method I should use, which is the most reliable way? I use a ACCESS DB becuse there is no heavy traffic on the site.

Any ideas?

Thanks /Speedy

Freon22
10-18-2005, 10:10 PM
There are a few ways of doing something like this. If all you want is to get a total count of all users on your site you can code this into your global.asa file.

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

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

Sub Session_OnStart
Session.Timeout = 10 ' minutes
Session("name") = ""
Application.Lock
Application("users") = Application("users") + 1
Application.Unlock
End Sub

Sub Session_OnEnd
' Decrease the active visitors count when the session ends.
Application.Lock
Application("users") = Application("users") - 1
Application.UnLock
End Sub
</SCRIPT>

Then this on each page that you want to display the total number of visiters.

Response.Write("<br>" & Application("users") & " Users Online" & "<br>")

But if you want names of users that have login to your site. Then it would be best to put a date/time stamp in your database when they login and each time they move to another page update the date/time stamp. You can then query the database for

Select name From YourTable Where strdatetime => '" & <%= DateAdd("N", -10, Now) %> & "';"

I haven't test this but this how I am planing to do one of my sites.
This will bring up everything Now minus 10 min. So if a user doesn't move to another page for more then 10 mins then his name will not come up. If you don't make the date time field a string you will have to encase the date/time in #s.