Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know online users of my web site

I am setting the value of Session["UserID"] to Id of logined user, so I can know who the user is. But I want to know all users logined my page, and show the list of them.

like image 606
Sessiz Saat Avatar asked Feb 14 '09 17:02

Sessiz Saat


3 Answers

Generally, you ask "How to know who has been active in the last x minutes."

Record their last activity time on each page entry, and then query that list to see who's been active in the last couple of minutes. You could extend that and record the last page they visited too, to know how many people are online, and how many people are on a specific page.

You could do this by adding just a couple fields to your user-table in the database. One for the lastActivityTime, and one for lastVisitedLocation.

like image 85
Sampson Avatar answered Oct 04 '22 03:10

Sampson


the main problem you have with logged in users is that there is no guaranteed way to ensure that the number is accurate, if someone closes their browser or kills it, or loses power, the only way you have of knowing that they aren't logged in, is when their session expires, so, by default this is 20 minutes... i'm not really into the idea of persisting this information into a database, although it is valid, the same problem remains, all you can accurately show is the number of sessions asp.net thinks are active not necessarily the number of users who are still using your site Jonathans answer is the best compromise as its a point in time measure rather than a guaranteed figure.

like image 26
Matt Avatar answered Oct 04 '22 02:10

Matt


you can use database sessions and then use it to keep track of logged in users, once you start using database sessions tracking becomes easy,

no of users online will be just count of the records in the table

and since you will be having records for each logged in user in the sessions table you will be able to get the names of the users logged in too.

like image 36
tHeSiD Avatar answered Oct 04 '22 03:10

tHeSiD