/ Forside/ Teknologi / Udvikling / ASP / Spørgsmål
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
ASP
#NavnPoint
smorch 9259
Harlekin 1866
molokyle 1040
Steffanst.. 758
gandalf 657
smilly 564
gibson 560
cumano 530
MouseKeep.. 480
10  Random 410
Asp som viser online users
Fra : Sialkot
Vist : 1229 gange
40 point
Dato : 21-07-07 17:29

Jeg har en webappilaktion hvor brugerne har mulighed på logge sig på med et brugernavn og password.

Jeg prøver arbejde med Asp skriptet som skal vise online users i en tabel. Hvis de online user er logget på skal der vises der usernavn..!..


Jeg har en scpript der gøre det....Men den gøre almulig osgså...som jeg ik fatter....nogen som kan gøre den ENKEL?
........................................................................
<%
'//[][][][][][][][][][][][][][] MWPX - NEXT ! [][][][][][][][][][][][][][][][][]//
'//[] All code, files, images, and layouts copyright (c) 2005 by: []//
'//[] Smiley, Stribling, Taylor, Vaz & Reaume []//
'//[] []//
'//[] Released April 2005                                         []//
'//[]                                                        []//
'//[] No portion of this code may be used in any other fashion without []//
'//[] the express written consent of all parties listed above. Any violation []//
'//[] of our copyright will be met with swift prosecution.                 []//
'//[]                                                        []//
'//[] This code is governed by our commercial license. []//
'//[] You are free to modify the code for your own portal site, but may []//
'//[] not receive any compensation for using our code. []//
'//[]                                                        []//
'//[] Support can be found at http://www.mwpx.com or by sending []//
'//[] Email to admin@mwpx.com                                      []//
'//[]                                                        []//
'//[][][][][][][][][][][][][][] MWPX - NEXT! [][][][][][][][][][][][][][][][[][]//
CurPageInfoChk = "1"
function CurPageInfo ()
   strOnlineQueryString = ChkActUsrUrl(Request.QueryString)
   PageName = "Active User List"
   PageAction = "Viewing<br>"
   PageLocation = "active_users.asp"
   CurPageInfo = PageAction & " " & "<a href=" & PageLocation & ">" & PageName & "</a>"
end function
%>
<!--#INCLUDE FILE="config.asp" -->
<!--#INCLUDE FILE="inc_functions.asp" -->
<!--#INCLUDE FILE="inc_top.asp" -->
<%
tempArr = split(strWebmaster, ",")
strSiteOwner = tempArr(0)

nRefreshTime = Request.Cookies(strTempCookieType & "Reload")

if Request.form("cookie") = "1" then
if strSetCookieToForum = 1 then
Response.Cookies(strTempCookieType & "Reload").Path = strTempCookieType
   end if
   Response.Cookies(strTempCookieType & "Reload") = Request.Form("RefreshTime")
   Response.Cookies(strTempCookieType & "Reload").expires = strForumTimeAdjust + 365
   nRefreshTime = Request.Form("RefreshTime")
end if

if nRefreshTime = "" then
   nRefreshTime = 0
end if
ActiveSince = Request.Cookies(strTempCookieType & "ActiveSince")
'## Do Cookie stuffs with show last date
if Request.form("cookie") = "2" then
   ActiveSince = Request.Form("ShowSinceDateTime")
if strSetCookieToForum = 1 then
Response.Cookies(strTempCookieType & "ActiveSince").Path = strTempCookieType
   end if
   Response.Cookies(strTempCookieType & "ActiveSince") = ActiveSince
end if


mypage = request("whichpage")

   If mypage = "" then
    mypage = 1
   end if

   mypagesize = request.cookies("paging")("pagesize")

   If mypagesize = "" then
    mypagesize = 15
   end if
%>
<script language="JavaScript">
<!--
function autoReload()
{
   document.ReloadFrm.submit()
}
//-->
</script>
<script language="JavaScript">
<!--
function SetLastDate()
{
   document.LastDateFrm.submit()
}
//-->
</script>
<script language="JavaScript">
<!--
function jumpTo(s) {if (s.selectedIndex != 0) top.location.href = s.options[s.selectedIndex].value;return 1;}
// -->
</script>
<table width="95%" border=0>
<tr>
<td >
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><img src="images/icons/icon_folder_open.gif" border="0">&nbsp;<a href="default.asp">Home</a><br>
<img src="images/icons/icon_bar.gif" border="0"><img src="images/icons/icon_folder_open_topic.gif" border="0">&nbsp;Active Users </font><font face="<% =strDefaultFontFace %>" size="<% =strFooterFontSize %>">(Last Updated <%=strForumTimeAdjust %>)</font>
</td>
<td align="right">
<form id="formEle" name="ReloadFrm" action="active_users.asp" method="post"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><br>
<select name="RefreshTime" size="1" onchange="autoReload();">
<option value="0" <% if nRefreshTime = "0" then Response.Write(" SELECTED")%>>Don't reload automatically</option>
<option value="1" <% if nRefreshTime = "1" then Response.Write(" SELECTED")%>>Reload page every minute</option>
<option value="5" <% if nRefreshTime = "5" then Response.Write(" SELECTED")%>>Reload page every 5 minutes</option>
<option value="10" <% if nRefreshTime = "10" then Response.Write(" SELECTED")%>>Reload page every 10 minutes</option>
<option value="15" <% if nRefreshTime = "15" then Response.Write(" SELECTED")%>>Reload page every 15 minutes</option>
<option value="30" <% if nRefreshTime = "30" then Response.Write(" SELECTED")%>>Reload page every 30 minutes</option>
</select>
<input type="hidden" name="Cookie" value="1">
</font>
</form>
</td>
</tr>
</table>
<SCRIPT>
<!--
if (document.ReloadFrm.RefreshTime.options[document.ReloadFrm.RefreshTime.selectedIndex].value > 0) {
   reloadTime = 60000 * document.ReloadFrm.RefreshTime.options[document.ReloadFrm.RefreshTime.selectedIndex].value
   self.setInterval('autoReload()', 60000 * document.ReloadFrm.RefreshTime.options[document.ReloadFrm.RefreshTime.selectedIndex].value)
}
//-->
</SCRIPT>
<%
mwpThemeTableCustomCode = "cellpadding=0 border=0 cellspacing=0 width=70% align=center"
mwpThemeBlock_open()
%>

<tr>
<td <%= mwpThemeBlock_subTitleCell %> align=center valign=top nowrap><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strHeadFontColor %>"><B>Username</B></FONT></td>
<%   if (mlev = 4 or mlev = 3) then %>
<td <%= mwpThemeBlock_subTitleCell %> align=center valign=top nowrap><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strHeadFontColor %>"><B>IP Address</B></FONT></td>
<%   end if %>
   <td <%= mwpThemeBlock_subTitleCell %> align=center valign=top nowrap><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strHeadFontColor %>"><B>Last Action</B></FONT></td>
<td <%= mwpThemeBlock_subTitleCell %> align=center valign=top nowrap><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strHeadFontColor %>"><B>Logged On</B></FONT></td>
<td <%= mwpThemeBlock_subTitleCell %> align=center valign=top nowrap><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strHeadFontColor %>"><B>Last Active</B></FONT></td>
<td <%= mwpThemeBlock_subTitleCell %> align=center valign=top nowrap><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strHeadFontColor %>"><B>Online Time</B></FONT></td>
</tr>
<%
   set rs = Server.CreateObject("ADODB.Recordset")
   '## Forum_SQL
   strSql ="SELECT " & strTablePrefix & "ONLINE.UserID, " & strTablePrefix & "ONLINE.UserIP, " & strTablePrefix & "ONLINE.M_BROWSE, " & strTablePrefix & "ONLINE.DateCreated, " & strTablePrefix & "ONLINE.LastChecked, " & strTablePrefix & "ONLINE.CheckedIn "
   strSql = strSql & " FROM " & strMemberTablePrefix & "ONLINE "
   strSql = strSql & " ORDER BY " & strTablePrefix & "ONLINE.DateCreated, " & strTablePrefix & "ONLINE.CheckedIn DESC"

   rs.cachesize = 20
   rs.open strSql, my_Conn, 3

   i = 0

   If rs.EOF or rs.BOF then '## No categories found in DB
      Response.Write ""
   Else

      rs.movefirst
      num = 0
      rs.pagesize = mypagesize
      maxpages = cint(rs.pagecount)
      maxrecs = cint(rs.pagesize)
      rs.absolutepage = mypage
      howmanyrecs = 0
      rec = 1
      do until rs.EOF or (rec = mypagesize+1)
         if strI = 0 then
            CColor = strAltForumCellColor
         else
            CColor = strForumCellColor
         end if

         strTheUserID = rs("UserID")
         strTheUserID = OnlineSQLdecode(strTheUserID)

         if Right(rs("UserID"), 5) <> "Guest" then
   strSql = "SELECT " & strMemberTablePrefix & "MEMBERS.MEMBER_ID, " & strMemberTablePrefix & "MEMBERS.M_NAME, " & strTablePrefix & "ONLINE.UserID "
   strSql = strSql & " FROM " & strTablePrefix & "MEMBERS, " & strTablePrefix & "ONLINE "
   strSql = strSql & " WHERE " & strMemberTablePrefix & "MEMBERS.M_NAME = '" & rs("UserID") & "' "
   set rsMember = my_Conn.Execute (strSql)
end if
if Right(rs("UserID"), 5) = "Guest" then
num = num + 1
end if

strOnlineDateCheckedIn = ChkDate(rs("CheckedIn"))
strOnlineDateCheckedIn = strOnlineDateCheckedIn & ChkTime(rs("CheckedIn"))
strOnlineLastDateChecked = ChkDate(rs("LastChecked"))
strOnlineLastDateChecked = strOnlineLastDateChecked & ChkTime(rs("LastChecked"))

strOnlineTotalTime = DateDiff("n",strOnlineDateCheckedIn,strOnlineLastDateChecked)

If strOnlineTotalTime > 60 then
' they must have been online for like an hour or so.
strOnlineHours = 0
do until strOnlineTotalTime < 60
strOnlineTotalTime = (strOnlineTotalTime - 60)
strOnlineHours = strOnlineHours + 1
loop
strOnlineTotalTime = strOnlineHours & " Hours " & strOnlineTotalTime & " Minutes"
Else
strOnlineTotalTime = strOnlineTotalTime & " Minutes"
End If

%>
<tr bgcolor="<% =CColor %>">
<% if Right(rs("UserID"), 5) = "Guest" then %>
<td valign="middle" align="center"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strDefaultFontColor %>">Guest #<% =num %></font></td>
<% else %>
<td valign="middle" align="center"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strDefaultFontColor %>">
<% if strUseExtendedProfile then
            Response.Write("<a href=""pop_profile.asp?mode=display&id="& rsMember("MEMBER_ID") & """>")
         else
            Response.Write("<a href=""JavaScriptenWindow2('pop_profile.asp?mode=display&id=" & rsMember("MEMBER_ID") & "')"">")
         end if
         Response.Write(rs("UserID") & "</a></font>")
%>
<% end if %>
<%   if mlev = 3 then %>
   <td valign="middle" align="center"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strDefaultFontColor %>"><% =rs("UserIP")%></font></td>
<%   end if
   if mlev = 4 then %>
   <td valign="middle" align="center"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strDefaultFontColor %>"><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<%=rs("UserIP")%>" target="_blank"><% =rs("UserIP")%></a></font></td>
<%   end if
   if lcase(rs("UserID"))= strSiteOwner and not lcase(strDBNTUserName) = strSiteOwner then
   LastUserAction = "Invisible"
   else
   LastUserAction = rs("M_BROWSE")
   end if
%>
<td valign="middle" align="center"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strDefaultFontColor %>"><% =LastUserAction%></A></font></td>
<td align="center" valign="middle" width="100" nowrap><font face="<% =strDefaultFontFace %>" size="<% =strFooterFontSize %>" color="<% =strDefaultFontColor %>"><%=strOnlineDateCheckedIn%></FONT></td>
<td align="center" valign="middle" width="100" nowrap><font face="<% =strDefaultFontFace %>" size="<% =strFooterFontSize %>" color="<% =strDefaultFontColor %>"><%=strOnlineLastDateChecked%></FONT></td>
<td align="center" valign="middle" width="100" nowrap><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>" color="<% =strDefaultFontColor %>"><%=strOnlineTotalTime%></FONT></td>
</tr>

<%
       rs.MoveNext
       strI = strI + 1
       if strI = 2 then
            strI = 0
         end if
       rec = rec + 1
      loop
   end if

mwpThemeBlock_close()%>
<table width="70%" align="right">
<tr>
<td width="60%">&nbsp;</td>
<td width="40%" align="left">
<% if maxpages > 1 then %>
   <table border=0>
   <tr>
   <td valign="top"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><b>Pages: </b></font></td>
   <td valign="top"><font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>"><% Call Paging() %></font></td>
   </tr>
   </table>
<% else %>

&nbsp;
<% end if %>
</td>
</tr>
</table>
<br><br>
<center>
<font face="<% =strDefaultFontFace %>" size="<% =strDefaultFontSize %>-1" color="<% =strCategoryFontColor %>">
<a href="default.asp">Return to Home</A>
</FONT>
</center>
<!--#INCLUDE FILE="inc_footer.asp" -->

<%
sub Paging()
   if maxpages > 1 then
      if Request.QueryString("whichpage") = "" then
         pge = 1
      else
         pge = Request.QueryString("whichpage")
      end if
      scriptname = request.servervariables("script_name")
      Response.Write("<table border=0 width=100% cellspacing=0 cellpadding=1 align=top><tr>")
      for counter = 1 to maxpages
         if counter <> cint(pge) then
            ref = "<td align=right bgcolor=" & strPageBGColor & "><font face=" & strDefaultFontFace & " size=" & strDefaultFontSize & ">" & "&nbsp;" & widenum(counter) & "<a href='" & scriptname
            ref = ref & "?whichpage=" & counter
            ref = ref & "&pagesize=" & request.cookies("paging")("pagesize")
            if top = "1" then
               ref = ref & ">"
               ref = ref & "</font><b><font face='" & strDefaultFontFace & "' "
               ref = ref & "color='" & strHeadFontColor & "'"
               ref = ref & ">" & counter & "</font></b></a></td>"
               Response.Write ref
            else
               ref = ref & "'>" & counter & "</font></a></td>"
               Response.Write ref
            end if
         else
            Response.Write("<td align=right bgcolor=" & strPageBGColor & "><font face=" & strDefaultFontFace & " size=" & strDefaultFontSize & ">" & "&nbsp;" & widenum(counter) & "<b>" & counter & "</b></font></td>")
         end if
         if counter mod 15 = 0 then
            Response.Write("</tr><tr>")
         end if
      next
      Response.Write("</tr></table>")
   end if
   top = "0"
end sub
%>

 
 
Kommentar
Fra : disken


Dato : 21-07-07 20:08

Prøv molokyle -n eller søg på ham, hjælper sikkert gerne.
Har du søgt HJÆLP på.
http://www.mwpx.com



Kommentar
Fra : disken


Dato : 21-07-07 20:11

Og understøtter din WEBUDBYDER = ASP
IKKE mange ???, prøv det først.

Kommentar
Fra : disken


Dato : 21-07-07 20:12

BTW_ pas på med scripts_ man ?? får i nakken = GRATIS


Kommentar
Fra : hr_hvalsoe


Dato : 22-07-07 11:48

Hej Sialkot

Det er oplagt at benytte Global.asa filen til dette formål.

Følgende kode indsættes i global.asa filen:

<script language="vbscript" runat="server">Sub Application_OnStart
Application("visitors")=0
End SubSub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End SubSub Session_OnEnd
Application.Lock
Application("visitors")=Application("visitors")-1
Application.UnLock
End Sub</script>

Efterfølgende kan du fra din ASP side angive følgende:

<html>
<head>
</head>
<body>
<p>
There are <%response.write(Application("visitors"))%>
online now!
</p>
</body>
</html>

Herved få du antallet at aktive brugere på en side.

Koden er taget fra http://www.w3schools.com/asp/asp_globalasa.asp

Vh
hr_hvalsoe

Kommentar
Fra : Sialkot


Dato : 22-07-07 12:52

Taaak....men jeg vil også have users navne vist i en tabel...hentet fra databasen

Kommentar
Fra : smorch


Dato : 23-07-07 20:37

Jeg har sådan et system, men jeg skal lige have modereret koden - det bliver først i morgen - hvilken database bruger du?

Kommentar
Fra : disken


Dato : 23-07-07 20:44

Citat
Taaak....men jeg vil også have users navne vist i en tabel...hentet fra databasen

Flere profiler gør det sikkert bedre...

Stopper HER OGSÅ

Accepteret svar
Fra : smorch

Modtaget 40 point
Dato : 24-07-07 10:29

Her er en global.asa og en asp fil users.asp.

Users.asp skal inkluderes i din default side / eller de sider du vil have vist online users på.

Scriptene kræver at du i din bruger database har et felt, der hedder login med værdi 0 eller 1.
Jeg går også hér ud fra at brugenavne står i et felt der hedder brugernavn og brugeren har et id - et tal i et felt der hedder UID.

Når bruger er loggget ind, skal bruger id og brugernavn lægges i to session, der hedder Session("UID") og session("brugernavn") og du skal kalde subben AddOnlineUser   
Call AddOnlineUser()
derfor skal users.asp være inkluderet i din login side også


For at vise brugere online skal du kalde subben WriteOnLineUsers()

<%=WriteOnLineUsers()%>

Antal online: <%=application("Taeller")=%>



Her er filerne: (Husk at rette databasestien og databasenavnet)

GLOBAL.ASA :

<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart
   SQL="update brugere set online=0"
   Set Conn2 = CreateObject("ADODB.Connection")
   Conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\web\blabla.dk\database\accesdatabase.mdb"
   set rs = Conn2.Execute( SQL )
   conn2.close
   set conn2=nothing
   set rs= nothing
End Sub

Sub Application_OnEnd

End Sub

Sub Session_OnStart
Session.Timeout = 20
Application.Lock
Application("OnlineUsers") = ","
Application.UnLock
Application.Lock
Application("visits")=Application("visits")+1
Application.UnLock
Application.Lock
application("Taeller")=application("Taeller")+1
Application.Unlock

End Sub

Sub Session_OnEnd
If Len(Session("UID")) > 0 Then
Application.Lock
Application("OnlineUsers") = Replace(Application("OnlineUsers"), Session("UID") & ",", "")
   SQL="update brugere set online=0 where uid="&Session("UID")
   Set Conn2 = CreateObject("ADODB.Connection")
   Conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\web\blabla.dk\database\accesdatabase.mdb"
   set rs = Conn2.Execute( SQL )
   conn2.close
   set conn2=nothing
   set rs= nothing
Application.UnLock
End If

Application.Lock
application("Taeller")=application("Taeller")-1
Application.Unlock
Application.Lock
application("brugere")=replace(application("brugere"), chr(9) & session("brugernavn"), "")
Application.Unlock
End Sub
</SCRIPT>




USERS.ASP :

<%@ language="VBSCRIPT" %>
<%
' --- procedure til at tilføje en online bruger ---
Sub AddOnlineUser()
Application.Lock
Application("OnlineUsers") = Application("Onlineusers") & Session("uid") & ","
Application.UnLock
End Sub
' --- funktion som retunerer antallet af online brugere ---
Function CountOnLineUsers()
Dim arrUsers
' --- lav et array med online brugere ---
arrUsers = Split(Application("Onlineusers"), ",")
' --- antallet af online brugere er altid størrelsen på arrayet -1 ---
CountOnLineUsers = UBound(arrUsers) - 1
   
End Function

' --- procedure til at udskrive online brugere ---
Sub WriteOnLineUsers()
Dim arrUsers
Dim n
' --- lav et array med online brugere ---
arrUsers = Split(Application("Onlineusers"), ",")
' --- udskriv liste ---
   Set Conn2 = CreateObject("ADODB.Connection")
   Set Rs = CreateObject("ADODB.Recordset")
   Conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\web\blabla.dk\database\accesdatabase.mdb"
%>
<table border="0" cellspacing="0" cellpadding="0">
<tr><td align="left" class="side_fokus_onlineliste" colspan="3">Bruger Online nu:</td></tr>
<tr><td>
<%

For n = 1 To UBound(arrUsers) -1
   if arrUsers(n)<>"" then
      SQL="SELECT UID, brugernavn, logon FROM brugere WHERE uid = "&arrUsers(n)
      response.Write(sql)
      set rs = Conn2.Execute( SQL )
      if not rs.eof then
         x=x+1
         y=2
         if x mod 2 = 0 then y=1
%>
         <span class="bruger<%= y %>">   
            <%=rs("brugernavn")%>
         </span><br>
<%   
      end if
   end if
Next
%>
</td></tr></table>
   <%
   conn2.close
   set conn2=nothing
   set rs= nothing
End Sub
%>



MvH
sMorCh

Godkendelse af svar
Fra : Sialkot


Dato : 26-07-07 12:25

Tak for svaret smorch.

Kommentar
Fra : smorch


Dato : 26-07-07 13:46

Sæl

Du har følgende muligheder
Eftersom du ikke er logget ind i systemet, kan du ikke skrive et indlæg til dette spørgsmål.

Hvis du ikke allerede er registreret, kan du gratis blive medlem, ved at trykke på "Bliv medlem" ude i menuen.
Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408914
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste