Page 1 of 1
How to get the count of sessions?
Posted: Thu Dec 02, 2010 9:03 am
by Aristona
Hi,
I have a page where users should login to browse the content. When they login, I create a session for them.
My question is;
1. How can I see the total count of current sessions?
2. How can I see the each username of sessions? (like Aristona in this case)
Thanks.
Re: How to get the count of sessions?
Posted: Thu Dec 02, 2010 9:40 am
by curlybracket
You have to use database, I'm not sure if it is possible to count sessions like that.
I think you have to create table for this purpose and put users data inisde. Gather data in the same place in your code where sessions are being created.
Re: How to get the count of sessions?
Posted: Thu Dec 02, 2010 10:17 am
by Aristona
curlybracket wrote:You have to use database, I'm not sure if it is possible to count sessions like that.
I think you have to create table for this purpose and put users data inisde. Gather data in the same place in your code where sessions are being created.
Thanks for the reply, but what about when someone closes the browser but doesn't click the logout button? Do I need to define idle duration and kick users automatically? If so, any examples on how can I do it?
Re: How to get the count of sessions?
Posted: Thu Dec 02, 2010 10:44 am
by curlybracket
You can store time of logging in this new table. Than you can refresh it after user's actions and check if last refresh is not older than session time. If it is - he probably closed his browser without logging out.
Re: How to get the count of sessions?
Posted: Thu Dec 02, 2010 3:35 pm
by Aristona
curlybracket wrote:You can store time of logging in this new table. Than you can refresh it after user's actions and check if last refresh is not older than session time. If it is - he probably closed his browser without logging out.
A db connection -> updating rows each time he visit a page won't be a problem with website's performance?
Re: How to get the count of sessions?
Posted: Thu Dec 02, 2010 6:58 pm
by curlybracket
It depends on the site. Counting logged users will usually be just an approximation. So you can update row only when user do some specific things, ie. updating database in some way or visiting home page. Or you can just assume that average visit time == 20 minutes and treat user as logged off after that time.