view connected users

What is the yii way to view connected users ?

I have a membership website and I want the connected users to b seen on the index page so want to know a way the get like id of connected user.

what you mean by connected users and id of connected users?

and what is your need… do you want that any user can see who is logged on your site or something else?

  1. By connected users I mean logged users

  2. Yes I want any user to se who is logged on the site

Then you need to decide how you will know that a user is still logged on (he can log on and close the browser for example)

One way would be to have a table… when a user logs on you save a record there with the user ID and the time…

on every action you update the time on that record so to know that a user is active

when the user logs out… you delete the record…

to display active users… you list the table… by checking the date that is max. XX min old…

I dont want that that. If he closes his browser he should be logged out

That seems the way to it (I’ll try)

how?

when a user clicks on "logout" the actionLogout() is executed… so you can add there the code for deleting the record…

but if the user logs in and closes the browser… your application don’t know that… and you will still have his record in the table… that’s why you need to check the time…

You may use CDbHttpSession as your session component. You can easily extend the session table for other columns like userId or username (your have to extend the CDbHttpSession class).

The session table contains a column called "expire". With help of this column, you are able to query for example the users which were active on your site within the last 3 minutes.