Avatar billede carparknorth Nybegynder
24. maj 2003 - 14:35 Der er 15 kommentarer og
1 løsning

Online Brugere / Gæster

Hejsa.

Prøv at tjekke: http://www.cdguiden.dk/SS_large_y1gsp1.gif

Hvis I kigger for for neden på billedet er noget der hedder Users Online.
Der er de besøgende delt op i brugere og gæster.

Hvordan gør jeg dette i ASP og hvis det er muligt uden database??
Avatar billede -master-d- Nybegynder
24. maj 2003 - 16:28 #1
Her er et forslag.

<%
Sub LogActiveUser
Dim strActiveUserList,strActiveGuestList
Dim intUserStart, intUserEnd
Dim strUser
Dim strDate

strActiveUserList = Application("ActiveUserList")
strActiveGuestList = Application("ActiveUserList")

If Instr(1, strActiveUserList, Session.SessionID) > 0 Then
Application.Lock
intUserStart = Instr(1, strActiveUserList, Session.SessionID)
intUserEnd = Instr(intUserStart, strActiveUserList, "|")
strUser = Mid(strActiveUserList, intUserStart, intUserEnd - intUserStart)
strActiveUserList = Replace(strActiveUserList, strUser, Session.SessionID & ":" & Now())
Application("ActiveUserList") = strActiveUserList
Application.UnLock
Elseif Instr(1, strActiveGuestList, Session.SessionID) > 0 Then
Application.Lock
intGuestStart = Instr(1, strActiveGuestList, Session.SessionID)
intGuestEnd = Instr(intGuestStart, strActiveGuestList, "|")
strGuest = Mid(strActiveGuestList, intGuestStart, intvEnd - intGuestStart)
strActiveGuestList = Replace(strActiveGuestList, strGuest, Session.SessionID & ":" & Now())
Application("ActiveGuestList") = strActiveGuestList
Application.UnLock
Else
Application.Lock
If session("loggedin") = false then
Application("ActiveUsers") = CInt(Application("ActiveUsers")) + 1
Application("ActiveUserList") = Application("ActiveUserList") & Session.SessionID & ":" & Now() & "|"
Else
Application("Activeguests") = CInt(Application("ActiveUsers")) + 1
Application("ActiveGuestList") = Application("ActiveUserList") & Session.SessionID & ":" & Now() & "|"
End If
Application.UnLock
End If
End Sub
%>

Så kan du hente dataene sådan her :

<%
Call LogActiveUser()
Response.Write "Guests : " & Application("ActiveGuest") & ",&nbsp;&nbsp;Users:" & Application("ActiveUsers")
%>


Det er lavet udfra dette eksempel.

Der mangler dog en cleanupfunktion. Den kommer bare rolig...
Avatar billede -master-d- Nybegynder
24. maj 2003 - 16:28 #2
Avatar billede -master-d- Nybegynder
24. maj 2003 - 16:34 #3
Her er en cleanup funktion

<%
Sub ActiveUserCleanup
Dim ix, ix2
Dim intUsers, intGuests
Dim strActiveUserList, strActiveGuestList
Dim aActiveUsers,aActivevs
Dim intActiveUserCleanupTime,intActiveGuestCleanupTime
Dim intActiveUserTimeout,intActiveGuestTimeout

intActiveUserCleanupTime = 1
intActiveUserTimeout = 20
intActiveGuestCleanupTime = 1
intActiveGuestTimeout = 20

If Application("ActiveUserList") = "" Then Exit Sub

If DateDiff("n", Application("ActiveUsersLastCleanup"), Now()) > intActiveUserCleanupTime Then

    Application.Lock
    Application("ActiveUsersLastCleanup") = Now()
    Application.Unlock

    intUsers = 0
    strActiveUserList = Application("ActiveUserList")
    strActiveUserList = Left(strActiveUserList, Len(strActiveUserList) - 1)

    aActiveUsers = Split(strActiveUserList, "|")

For ix = 0 To UBound(aActiveUsers)
    If DateDiff("n", Mid(aActiveUsers(ix), Instr(1, aActiveUsers(ix), ":") + 1, Len(aActiveUsers(ix))), Now()) > intActiveUserTimeout Then
        aActiveUsers(ix) = "XXXX"
    Else
        intUsers = intUsers + 1
    End If
Next

strActiveUserList = Join(aActiveUsers, "|") & "|"
strActiveUserList = Replace(strActiveUserList, "XXXX|", "")

    Application.Lock
    Application("ActiveUserList") = strActiveUserList
    Application("ActiveUsers") = intUsers
    Application.UnLock

End If

'For guests only
If Application("ActiveGuestList") = "" Then Exit Sub

If DateDiff("n", Application("ActiveGuestLastCleanup"), Now()) > intActiveGuestCleanupTime Then

    Application.Lock
    Application("ActiveGuestLastCleanup") = Now()
    Application.Unlock

    intUsers = 0
    strActiveGuestList = Application("ActiveGuestList")
    strActiveGuestList = Left(strActiveGuestList, Len(strActiveGuestList) - 1)

    aActiveGuests = Split(strActiveGuestList, "|")

For ix = 0 To UBound(aActiveGuests)
    If DateDiff("n", Mid(aActiveGuests(ix), Instr(1, aActiveGuests(ix2), ":") + 1, Len(aActiveGuests(ix2))), Now()) > intActiveGuestTimeout Then
        aActiveGuests(ix2) = "XXXX"
    Else
        intGuests = intGuests + 1
    End If
Next

strActiveGuestList = Join(aActiveGuests, "|") & "|"
strActiveGuestList = Replace(strActiveGuestList, "XXXX|", "")

    Application.Lock
    Application("ActiveGuestList") = strActiveGuestList
    Application("ActiveGuests") = intGuests
    Application.UnLock

End If

End Sub
%>

Så skal du bare lige huske at kalde funktionen på denne måde.

<%
Call LogActiveUser()
Call ActiveUserCleanup()

Response.Write "Guests : " & Application("ActiveGuest") & ",&nbsp;&nbsp;Users:" & Application("ActiveUsers")
%>
Avatar billede -master-d- Nybegynder
24. maj 2003 - 16:36 #4
Og så skal du når du i din login funktion. Lige tilføje

<%
'Når man logger ind
session("loggedin") = true
'når man logger ud
session("loggedin") = false
%>
Avatar billede carparknorth Nybegynder
24. maj 2003 - 17:07 #5
det ser rigtig fedt ud!

Du har klart fortjent pointene...

lige et spg til. Er det muligt at få vist brugernavnene på det brugere (ikke gæster) der er logget ind?
Avatar billede -master-d- Nybegynder
24. maj 2003 - 17:36 #6
Ja, det er det. Men så skal du nok gå lidt mere i detaljer med hvordan din login funktion virker.
Avatar billede -master-d- Nybegynder
24. maj 2003 - 17:54 #7
Har du afprøvet det ? For ved mig ser det ud som om der er nogle småfejl...
Avatar billede -master-d- Nybegynder
24. maj 2003 - 18:03 #8
Her er et eksempel et scriptet hvor det virker.

<html>

<head>
<title>Ny side 1</title>
</head>

<body>
<%
session("loggedin") = false

Sub LogActiveUser
Dim strActiveUserList, strActiveGuestList
Dim intUserStart, intUserEnd
Dim strUser
Dim strDate

strActiveUserList = Application("ActiveUserList")
strActiveGuestList = Application("ActiveGuestList")

If Instr(1, strActiveUserList, Session.SessionID) > 0 Then

Application.Lock
intUserStart = Instr(1, strActiveUserList, Session.SessionID)
intUserEnd = Instr(intUserStart, strActiveUserList, "|")
strUser = Mid(strActiveUserList, intUserStart, intUserEnd - intUserStart)
strActiveUserList = Replace(strActiveUserList, strUser, Session.SessionID & ":" & Now())
Application("ActiveUserList") = strActiveUserList
Application.UnLock

Elseif Instr(1, strActiveGuestList, Session.SessionID) > 0 Then

Application.Lock
intGuestStart = Instr(1, strActiveGuestList, Session.SessionID)
intGuestEnd = Instr(intGuestStart, strActiveGuestList, "|")
strGuest = Mid(strActiveGuestList, intGuestStart, intGuestEnd - intGuestStart)
strActiveGuestList = Replace(strActiveGuestList, strGuest, Session.SessionID & ":" & Now())
Application("ActiveGuestList") = strActiveGuestList
Application.UnLock

Else

Application.Lock
If Session("loggedin") = "Ja" then
Application("ActiveUsers") = CInt(Application("ActiveUsers")) + 2
Application("ActiveUserList") = Application("ActiveUserList") & Session.SessionID & ":" & Now() & "|"
Else
Application("ActiveGuest") = CInt(Application("ActiveGuest")) + 1
Application("ActiveGuestList") = Application("ActiveGuestList") & Session.SessionID & ":" & Now() & "|"
End If
Application.UnLock
End If
End Sub

'************************************************************************

Sub ActiveUserCleanup
Dim ix, ix2
Dim intUsers, intGuests
Dim strActiveUserList, strActiveGuestList
Dim aActiveUsers,aActivevs
Dim intActiveUserCleanupTime,intActiveGuestCleanupTime
Dim intActiveUserTimeout,intActiveGuestTimeout

intActiveUserCleanupTime = 1
intActiveUserTimeout = 20
intActiveGuestCleanupTime = 1
intActiveGuestTimeout = 20

If Application("ActiveUserList") = "" Then Exit Sub

If DateDiff("n", Application("ActiveUsersLastCleanup"), Now()) > intActiveUserCleanupTime Then

    Application.Lock
    Application("ActiveUsersLastCleanup") = Now()
    Application.Unlock

    intUsers = 0
    strActiveUserList = Application("ActiveUserList")
    strActiveUserList = Left(strActiveUserList, Len(strActiveUserList) - 1)

    aActiveUsers = Split(strActiveUserList, "|")

For ix = 0 To UBound(aActiveUsers)
    If DateDiff("n", Mid(aActiveUsers(ix), Instr(1, aActiveUsers(ix), ":") + 1, Len(aActiveUsers(ix))), Now()) > intActiveUserTimeout Then
        aActiveUsers(ix) = "XXXX"
    Else
        intUsers = intUsers + 1
    End If
Next

strActiveUserList = Join(aActiveUsers, "|") & "|"
strActiveUserList = Replace(strActiveUserList, "XXXX|", "")

    Application.Lock
    Application("ActiveUserList") = strActiveUserList
    Application("ActiveUsers") = intUsers
    Application.UnLock

End If

'For guests only
If Application("ActiveGuestList") = "" Then Exit Sub

If DateDiff("n", Application("ActiveGuestLastCleanup"), Now()) > intActiveGuestCleanupTime Then

    Application.Lock
    Application("ActiveGuestLastCleanup") = Now()
    Application.Unlock

    intUsers = 0
    strActiveGuestList = Application("ActiveGuestList")
    strActiveGuestList = Left(strActiveGuestList, Len(strActiveGuestList) - 1)

    aActiveGuests = Split(strActiveGuestList, "|")

For ix = 0 To UBound(aActiveGuests)
    If DateDiff("n", Mid(aActiveGuests(ix), Instr(1, aActiveGuests(ix2), ":") + 1, Len(aActiveGuests(ix2))), Now()) > intActiveGuestTimeout Then
        aActiveGuests(ix2) = "XXXX"
    Else
        intGuests = intGuests + 1
    End If
Next

strActiveGuestList = Join(aActiveGuests, "|") & "|"
strActiveGuestList = Replace(strActiveGuestList, "XXXX|", "")

    Application.Lock
    Application("ActiveGuestList") = strActiveGuestList
    Application("ActiveGuest") = intGuests
    Application.UnLock

End If

End Sub

'**************************************************************************************'

%>

Online users<br>

<%
Call LogActiveUser()
Call ActiveUserCleanup()

Response.Write "Guests : " & Application("ActiveGuest") & ",&nbsp;Users:" & Application("ActiveUsers")
%>
</body>

</html>



Den med brugernavnene skal jeg bruge lidt mere info til at bygge.
Avatar billede carparknorth Nybegynder
24. maj 2003 - 18:03 #9
Jeg har ikke afprøvet det, men det vil jeg lige om lidt.

Jeg vil gætte på at første gang de besøgende kommer på siden vil de blive talt som brugere i stedet for gæster.

Mit login script er ikke så svært.

<%

' LOGIN.ASP

Brugernavn = request.form("Brugernavn")
Kodeord    = request.form("Kodeord")
GemKodeord = request.form("GemKodeord")

sql = "select count(*) as Total from tblMedlemmer where Brugernavn = '"&Brugernavn&"' and Password = '"&Kodeord&"'"
set rs = forbind.execute(sql)

if rs("Total") = 1 then
session("LoggetInd") = true
session("Brugernavn") = Brugernavn

if GemKodeord = "Ja" then
Response.Cookies("Brugernavn")=Brugernavn
Response.Cookies("Kodeord")=Kodeord
else
Response.Cookies("Brugernavn") = ""
Response.Cookies("Kodeord") = ""
end if

response.redirect(""&request.servervariables("HTTP_REFERER")&"")


else
response.write("FEJL")
end if


%>
Avatar billede -master-d- Nybegynder
24. maj 2003 - 18:19 #10
Den jeg smed har også en lille fejl.

Application("ActiveUsers") = CInt(Application("ActiveUsers")) + 2

Skal selvfølgelig rettes til

Application("ActiveUsers") = CInt(Application("ActiveUsers")) + 1
Avatar billede carparknorth Nybegynder
24. maj 2003 - 18:22 #11
jep, den havde jeg set... :-)  undrede mig også lidt over den...
Avatar billede -master-d- Nybegynder
24. maj 2003 - 18:59 #12
Og denne

session("loggedin") = false

Skal helt væk.
Avatar billede carparknorth Nybegynder
24. maj 2003 - 19:05 #13
godt, den i toppen er også væk nu.

Hvordan laver jeg den liste? der må meget gerne være en begrænsning på, altså bare listen nævner en 2-3 navne og sætter "..." efter, så er det fint.. :-)
Avatar billede -master-d- Nybegynder
24. maj 2003 - 20:13 #14
Her er et eksempel på det du snakker om.

http://www.websamba.com/denpei/exp/356530/default.asp

INFO :

Brugernavn  = test
Password = test

Du kan hente sourcen her :

http://www.websamba.com/denpei/exp/356530/356530.zip
Avatar billede carparknorth Nybegynder
24. maj 2003 - 20:38 #15
1000 tak for alt din hjælp!!
Avatar billede -master-d- Nybegynder
24. maj 2003 - 20:42 #16
Det var så lidt... Tak for pointene :D
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