Avatar billede none01 Nybegynder
19. marts 2006 - 17:06

Stats script virker ikke helt

Hej, jeg har et problem med et stats script som min side køre med, som skal vise hvormange brugere der var online de sidste 5 minuter.
Men problemet er at hvis en bruger har 2 browsere åben til min side, så tæller min stats kode dem bægge.
Jeg tænkte om der var en måde på at den tæller en person pr. ip?
det her er globel.asa filen:

<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
    ' 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.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>

Det er selve stats koden:

<!--#include file="config.asp" -->
<%
'Here we find the ip address of the user
ipaddr = Request.ServerVariables("REMOTE_ADDR")
'here we open the database and look if the ip address of the user is in the database
strsql = "SELECT * FROM stats where ip='" & ipaddr & "'"
set rs = con.execute(strsql)
if rs.EOF then
'If the ip address isn't in the database, then we are adding it
  strsql2 = "INSERT INTO stats (ip) "
  strsql2 = strsql2 & "values('" & ipaddr & "')"
  con.execute(strsql2)
end if
set rs = nothing

'Here we print out how meny users there are online for the past 5 minutes, Application("users") comes from the global.asa file
    if Application("users") = "1" then
    Response.Write(ouser)
    else
    Response.Write(musers)
    end if
'Here we print out how meny users there where on the page in all
strsql3 = "SELECT * FROM stats ORDER BY id DESC LIMIT 0,1"
set rs = con.execute(strsql3)
id = rs("id")
Response.Write(allusersp1 &"" & id & "" & allusersp2)
set rs = nothing
con.Close
set con = nothing
%>

Og det er koden fra min engelske lang fil:

'Stats text
  ouser = "There was " & Application("users") & " user online for the past 5 minutes."
  musers = "There where " & Application("users") & " users online for the past 5 minutes."
  allusersp1 = "<br /><br />There where "
  allusersp2 = " different users on this page in all."
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester