Ok this may be long but here it is, I got this code from a forum and it works ok displaying the results on a page, but I want to add the username so it displays who is logged in.
PLease help I have added 2 lines '-------
But it doesnt work
<object runat="Server" scope="Application"
id="rstActiveUsers" progid="ADODB.Recordset">
</object>
<script language="VBScript" runat="Server">
Sub Application_OnStart()
Const adInteger = 3
Const adVarChar = 200
Const adDate = 7
rstActiveUsers.Fields.Append "id", adInteger
rstActiveUsers.Fields.Append "ip", adVarChar, 15
rstActiveUsers.Fields.Append "browser",adVarChar,25
'---I added this------
rstActiveUsers.Fields.Append "UserID", adVarChar, 255
rstActiveUsers.Fields.Append "started", adDate
rstActiveUsers.Open
End Sub
Sub Session_OnStart()
Session.Timeout = 20
Session("Start"
= Now()
If Not rstActiveUsers.EOF Then rstActiveUsers.MoveLast
rstActiveUsers.AddNew
rstActiveUsers.Fields("id"
.Value = _
Session.SessionID
rstActiveUsers.Fields("ip"
.Value = _
Request.ServerVariables("REMOTE_HOST"
rstActiveUsers.Fields("browser"
.Value = _
Request.ServerVariables("HTTP_USER_AGENT"
rstActiveUsers.Fields("started"
.Value = _
Now()
'----------I added this but no Luck ---------
rstActiveUsers.Fields("UserID"
.Value = _
session("UserID"
rstActiveUsers.Update
End Sub
Sub Session_OnEnd()
Const adSearchForward = 1
Const adBookmarkFirst = 1
Const adAffectCurrent = 1
rstActiveUsers.Find "id = " & Session.SessionID, _
0, adSearchForward, adBookmarkFirst
If Not rstActiveUsers.EOF Then
rstActiveUsers.Delete adAffectCurrent
End If
End Sub
Sub Application_OnEnd()
rstActiveUsers.Close
End Sub
</script>
Then On show_users.asp
<%
If rstActiveUsers.RecordCount > 0 Then
rstActiveUsers.MoveFirst
Response.Write "<table border=""1"">" & vbCrLf
Response.Write " <thead>" & vbCrLf
Response.Write " <th>User Name</td>" & vbCrLf
Response.Write " <th>Session Id</td>" & vbCrLf
Response.Write " <th>Session Start Time</th>" & vbCrLf
Response.Write " </thead>" & vbCrLf
Do While Not rstActiveUsers.EOF
Response.Write " <tr>" & vbCrLf
Response.Write " <td>" & rstActiveUsers.Fields("UserID"
.Value & "</td>" & vbCrLf
Response.Write " <td>" & rstActiveUsers.Fields("id"
.Value & "</td>" & vbCrLf
Response.Write " <td>" & rstActiveUsers.Fields("started"
.Value & "</td>" & vbCrLf
Response.Write " </tr>" & vbCrLf
rstActiveUsers.MoveNext
Loop
Response.Write "</table>" & vbCrLf
End If
%>
PLease help I have added 2 lines '-------
But it doesnt work
<object runat="Server" scope="Application"
id="rstActiveUsers" progid="ADODB.Recordset">
</object>
<script language="VBScript" runat="Server">
Sub Application_OnStart()
Const adInteger = 3
Const adVarChar = 200
Const adDate = 7
rstActiveUsers.Fields.Append "id", adInteger
rstActiveUsers.Fields.Append "ip", adVarChar, 15
rstActiveUsers.Fields.Append "browser",adVarChar,25
'---I added this------
rstActiveUsers.Fields.Append "UserID", adVarChar, 255
rstActiveUsers.Fields.Append "started", adDate
rstActiveUsers.Open
End Sub
Sub Session_OnStart()
Session.Timeout = 20
Session("Start"
If Not rstActiveUsers.EOF Then rstActiveUsers.MoveLast
rstActiveUsers.AddNew
rstActiveUsers.Fields("id"
Session.SessionID
rstActiveUsers.Fields("ip"
Request.ServerVariables("REMOTE_HOST"
rstActiveUsers.Fields("browser"
Request.ServerVariables("HTTP_USER_AGENT"
rstActiveUsers.Fields("started"
Now()
'----------I added this but no Luck ---------
rstActiveUsers.Fields("UserID"
session("UserID"
rstActiveUsers.Update
End Sub
Sub Session_OnEnd()
Const adSearchForward = 1
Const adBookmarkFirst = 1
Const adAffectCurrent = 1
rstActiveUsers.Find "id = " & Session.SessionID, _
0, adSearchForward, adBookmarkFirst
If Not rstActiveUsers.EOF Then
rstActiveUsers.Delete adAffectCurrent
End If
End Sub
Sub Application_OnEnd()
rstActiveUsers.Close
End Sub
</script>
Then On show_users.asp
<%
If rstActiveUsers.RecordCount > 0 Then
rstActiveUsers.MoveFirst
Response.Write "<table border=""1"">" & vbCrLf
Response.Write " <thead>" & vbCrLf
Response.Write " <th>User Name</td>" & vbCrLf
Response.Write " <th>Session Id</td>" & vbCrLf
Response.Write " <th>Session Start Time</th>" & vbCrLf
Response.Write " </thead>" & vbCrLf
Do While Not rstActiveUsers.EOF
Response.Write " <tr>" & vbCrLf
Response.Write " <td>" & rstActiveUsers.Fields("UserID"
Response.Write " <td>" & rstActiveUsers.Fields("id"
Response.Write " <td>" & rstActiveUsers.Fields("started"
Response.Write " </tr>" & vbCrLf
rstActiveUsers.MoveNext
Loop
Response.Write "</table>" & vbCrLf
End If
%>