ckroon
Posts: 869
|
| Posted: 12/16/2007, 8:37 PM |
|
Anyone got a snippet of code that will allow me to show the current number of logged in users?
Mysql/php
Thanks!
_________________
Walter Kempees...you are dearly missed. |
 |
 |
Aaron
Posts: 145
|
| Posted: 01/03/2008, 10:12 AM |
|
This would totally depend on your database structure. As users log in, you will have to set a flag in your database to indicate if the user is logged in or not. This in itself leads to the issue of, what happens if a user(s) do not logout? You will have to create some sort of auto-logout feature.
Anyway, assuming this has all been done, you can create a query to SELECT the COUNT of people where logged-in is equal to 1 (or true or whatever you use). Then display the record count.
I believe this has been addressed a few times in the forums.
|
 |
 |
DonB
|
| Posted: 01/08/2008, 10:28 AM |
|
Most (if not all) implementations of this are simply a query of 'timestamp
>= some threshold' (e.g. 10 minutes ago) You update their timestamp in the
users table when they log in and on every page they access. And, yes, the
'number of logged in users' is only approximate, and a bit wasteful of
database resources as you are doing lots of relatively-pointless updates.
--
DonB
http://ccswiki.gotodon.net
"Aaron" <Aaron@forum.codecharge> wrote in message
news:5477d257099889@news.codecharge.com...
> This would totally depend on your database structure. As users log in, you
> will
> have to set a flag in your database to indicate if the user is logged in
> or not.
> This in itself leads to the issue of, what happens if a user(s) do not
> logout?
> You will have to create some sort of auto-logout feature.
>
> Anyway, assuming this has all been done, you can create a query to SELECT
> the
> COUNT of people where logged-in is equal to 1 (or true or whatever you
> use).
> Then display the record count.
>
> I believe this has been addressed a few times in the forums.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
>
|
|
|
 |
|