Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Names of Logged-in users 5

Status
Not open for further replies.

schase

Technical User
Sep 7, 2001
1,756
0
0
US
We want to show in a cell the UserID's of the users currently logged-in. and have it auto log-out when they close the browser or after like 20 minutes.

Which is the best way to accomplish this?

Either make a field update in a table to Online - then display the ones that = "online"

or another way?
 
Put all the names into a session variable and log time... you could have a multi-dimensional array to hold both of these information.
Regards gsc1ugs
"Cant see wood for tree's...!"
 
wow,

ok, and while I've played a little with session variables page to page

I havnt dived into global.asa

how would I start?
 
I think there's a better way to track this... look for user link9.. seems to know alot about this. Regards gsc1ugs
"Cant see wood for tree's...!"
 
Using an application array for something like this simply won't work. In theory, you could make it work, but implementing it would make your server very very unhappy.

I would suggest using a database table to keep track of the users. You could put an INSERT statement for the table during your login, passing in the username, and then have a session_OnEnd event in your global.asa file that would pass the database a username for a simple DELETE statment.

Then just display all the records from that table to create your loggedUsers list.

:)
paul
penny1.gif
penny1.gif
 
ok so update is a no-go then?

how or what kind of event statement would I do?
 
Either way would work, I think. In your scenario, you would have the extra column in your users table, which would be a bit field (1/0) called 'online'

Then, upon login, you just issue:

UPDATE users SET online = 1 WHERE userName = 'userName'

where username is their login. You'll also wanna put that username into a session variable for use in your session_OnEnd event in your global.asa file later.

That event would look like:

sub session_OnEnd()
dim sql, con
set con = server.createObject("ADODB.Connection")
con.open connectionString
sql = "UPDATE users SET online = 0 WHERE userName = '" & session("userName") & "'"
con.execute sql
set con = nothing
end sub

and then, to display the list of users, just open a recordset with the following command:

SELECT userName FROM users WHERE online = 1

penny1.gif
penny1.gif
 
hmmmm gottchya

I've already got a field setup, and login sets the field to "online" but this happens on login.asp

the script I have or had is extremely similiar

but I think It wasnt setting the username session correctly

should I do the UPDATE users SET online = 1 WHERE userName = 'userName'
in the global.asa or in login where I have it?

 
leave that in the login.asp

the method where you knock it back to 0, though, will go in the global.asa
penny1.gif
penny1.gif
 
ok, will try - as soon as our provider line comes back up.

lol gotta love the telephone company

Thank you Link
 
Hi guys, I've read your posts and I found them very useful, 'cause I'm developing similar functions.
I've some problem with the global.asa session_onend() sub, in fact it looks like this sub is not called.
I mean:
- I open my web site and the OnLine fields is correctly set to 1 ( I do this in the home.asp page, not in Session_onStart())
- I close my browser (or move to a new site) and the fields is not set to 0, as if the session_onend() sub didn't raise.

Can someone help me?
Thanks a lot in advance, David
 
But Link9,
The problem can occur with the way you suggested is that
if user doesnt manually log out but close the browser then session will be there for 20 default minutes.

In this case will SESSION_ONEND will fire ????????

Rushi Shroff
 
To be honest, I can't give a good answer to that question. I really try to steer myself away from session variables, and therefore don't use the global.asa file. In theory, when a session times out, I would think that the session_OnEnd would fire, but like I said, I can't say for sure, and so it'd need to be tested to make sure.

Many sites do have a user counter (watered down version of the userName situation schase has asked about), and I don't see how that could work properly unless it did fire on timeout, since my experience has been that most ppl won't click a "logout" button unless they think sensitive info is at stake. My strong guess is that it will fire.
penny1.gif
penny1.gif
 
hmmmm

it doesnt like the online part
Microsoft VBScript compilation error '800a0401'

Expected end of statement

/login.asp, line 34

UPDATE Membersragol SET online_status=1 WHERE UserID = svUserID

and it points to the SET.

I've got it tucked in this script.

f Membersragol__strUserID <> &quot;xyz&quot; then
If Not Membersragol.EOF Then
Session(&quot;svUserID&quot;) = (Membersragol.Fields.Item(&quot;UserID&quot;).Value)
Session(&quot;svPassword&quot;) = (Membersragol.Fields.Item(&quot;Password&quot;).Value)
Session(&quot;svAccessGroup&quot;) = (Membersragol.Fields.Item(&quot;AccessGroup&quot;).Value)
Session(&quot;ID&quot;) = (Membersragol.Fields.Item(&quot;ID&quot;).Value)
strHomepage = Membersragol.Fields.Item(&quot;HomePage&quot;).Value
Session(&quot;blnIsUserGood&quot;) = True
If request.form(&quot;Password&quot;) = membersragol(&quot;Password&quot;) then
UPDATE Membersragol SET online_status=1 WHERE UserID = svUserID
end if
Response.Redirect(strHomePage)
Else
Response.Redirect &quot;login.asp&quot;
End If
End If
 
You can't just issue the statement outright. You must assign it to a variable, and then exeucute the statement on your connection object, so:

If request.form(&quot;Password&quot;) = membersragol(&quot;Password&quot;) then
UPDATE Membersragol SET online_status=1 WHERE UserID = svUserID
end if

should resemble:

If request.form(&quot;Password&quot;) = membersragol(&quot;Password&quot;) then
dim sql
sql = &quot;UPDATE Membersragol SET online_status=1 WHERE UserID = '&quot; & session(&quot;svUserID&quot;) & &quot;'&quot;
connectionObject.execute(sql)
end if

where connectionObject is the same connection object you use to open your recordset.

penny1.gif
penny1.gif
 
i'm missing something somewhere I get this error.

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Membersragol.execute'

/login.asp, line 35


on this recordset and code

<%
set Membersragol = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Membersragol.ActiveConnection = MM_membersragol_STRING
Membersragol.Source = &quot;SELECT * FROM Membersragol WHERE UserID = '&quot; + Replace(Membersragol__strUserID, &quot;'&quot;, &quot;''&quot;) + &quot;' AND Password = '&quot; + Replace(Membersragol__strPassword, &quot;'&quot;, &quot;''&quot;) + &quot;'&quot;
Membersragol.CursorType = 0
Membersragol.CursorLocation = 2
Membersragol.LockType = 3
Membersragol.Open()
Membersragol_numRows = 0
%>
<%
If Membersragol__strUserID <> &quot;xyz&quot; then
If Not Membersragol.EOF Then
Session(&quot;svUserID&quot;) = (Membersragol.Fields.Item(&quot;UserID&quot;).Value)
Session(&quot;svPassword&quot;) = (Membersragol.Fields.Item(&quot;Password&quot;).Value)
Session(&quot;svAccessGroup&quot;) = (Membersragol.Fields.Item(&quot;AccessGroup&quot;).Value)
Session(&quot;ID&quot;) = (Membersragol.Fields.Item(&quot;ID&quot;).Value)
strHomepage = Membersragol.Fields.Item(&quot;HomePage&quot;).Value
Session(&quot;blnIsUserGood&quot;) = True
If request.form(&quot;Password&quot;) = membersragol(&quot;Password&quot;) then
dim sql
sql = &quot;UPDATE Membersragol SET online_status=1 WHERE UserID = '&quot; & session(&quot;svUserID&quot;) & &quot;'&quot;
Membersragol.execute(sql)
end if
Response.Redirect(strHomePage)
Else
Response.Redirect &quot;login.asp&quot;
End If
End If
%>
 
Membersragol is your recordset, not your connection.

When you opened your recordset, you did not create a connection. Consider explicitly creating a connection, and using that throughout your code, rather than the implicit creation of a connection object, which is what happens when you simply pass in a connection string:

dim con, Membersragol
set con = server.createObject(&quot;ADODB.Connection&quot;)
set Membersragol = Server.CreateObject(&quot;ADODB.Recordset&quot;)

con.open MM_membersragol_STRING

Membersragol.ActiveConnection = con

---------------

con.execute sql

set Membersragol = nothing
set con = nothing

-

added the cleanup there on the last two lines. Always best to set your objects = nothing when you're through with them. It'll keep those resources freed up.

penny1.gif
penny1.gif
 
Just to add in a comment about the global.asa...

I've created exactly what you're talking about, however my site is for limited users ( <200 ) so I used the application scope to accomplish this. First off, just want to explain how the sesion_onend works...

As soon as you connect to the server, the session_onstart fires. Now, whenever your session ends, just before it ends, the session_onend fires within the global.asa. If you have a logout button/link on your site and use session.abandon, that will fire the session_onend event right away. However, if the user simply closes the browser, while they cannot reconnect to the server on the same session, the session still lays on your server until it times out (usually 20 minutes) at which time the session_onend event will THEN fire. So if they close their browser without logging out, it'll take the length of the session scope to alter it.

I am using the application scope to store current users. Since an application array is not aloud, I created an application string. Every time a user logs into the site, their name is added to the end of the string...so it may look somthing like this

application(&quot;users&quot;) = &quot;Chris, John, Sarah, Dick, Penny, Spot&quot;

Now when they users go to the page that lists all the current users logged online, I simply split the app. variable into a local array and display like so,

<%
Dim users, i

users = Split(application(&quot;users&quot;),&quot;, &quot;)
For i = 0 to UBOUND(users)
response.write(users(i) & &quot;<BR>&quot;)
Next
%>

Then all there is left to do is when the session_onend fires (when the user logges off or the session times-out), use somthing like:

application(&quot;users&quot;) = Trim(Replace(application(&quot;users&quot;), session(&quot;userName&quot;), &quot;&quot;))

And that'll remove their name from the application variable string.


Hope this explains the application side a little more and how the session_onend works.




-Ovatvvon :-Q
 
Dear Ovatvvon ,
thnX for long explaination.
Can you give me code for Shopping cart by session variables..??

Sameway we do it in session_Onstart event Naaah !!!

Rushi Shroff
 
Well got one half correct.

But there has to be something where it isnt either recognizing the session for ID or UserID or something

It will log in fine - changes the online status to 1, but when I do logout or wait over 20 minutes - nothing.

I'm wondering how much of this is due to the combination of UltraDeveloper code and hand coding - even though I'm keeping the recordset names the same.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top