how to count logged users in php

Hi all,

any way to count the number of users i have logged into my site?

any help/code appreciated,

craig
snowinfo [ Di, 22 April 2008 21:05 ] [ ID #1947868 ]

Re: how to count logged users in php

On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
> Hi all,
> any way to count the number of users i have logged into my site?
> any help/code appreciated,
> craig

Do you actually have people authenticating with usernames/passwords,
or are you just looking to see how many people (unique users) have hit
your site?
venti [ Di, 22 April 2008 21:09 ] [ ID #1947869 ]

Re: how to count logged users in php

On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
> On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> > Hi all,
> > any way to count the number of users i have logged into my site?
> > any help/code appreciated,
> > craig
>
> Do you actually have people authenticating with usernames/passwords,
> or are you just looking to see how many people (unique users) have hit
> your site?

I have them logging in first, set by a session, so I just want to say
'There are X users logged in' and then list the usernames.

That kinda thing

Cheers
snowinfo [ Di, 22 April 2008 21:14 ] [ ID #1947870 ]

Re: how to count logged users in php

On Tue, 22 Apr 2008 21:14:13 +0200, <snowinfo [at] gmail.com> wrote:

> On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
>> On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>>
>> > Hi all,
>> > any way to count the number of users i have logged into my site?
>> > any help/code appreciated,
>> > craig
>>
>> Do you actually have people authenticating with usernames/passwords,
>> or are you just looking to see how many people (unique users) have hit
>> your site?
>
> I have them logging in first, set by a session, so I just want to say
> 'There are X users logged in' and then list the usernames.

1) Preferably use a database, have a table active_users
2) On each request with a session & logged in user, either insert a record
with the user-id with a timestamp (or datetime) field, with the current
time, or update an allready existing record with that information (if
MySQL: ON DUPLICATE KEY UPDATE saves a lot of hassle).
3) On checking for active users, remove all entries from the active_users
table with updated more than X minutes ago (X is your choice).
4) Display the list in active users.

1-3 are even easier (and more reliable) if you've taken to storing
sessions in the database with a custom handler using
session_set_save_handler(), but if you don't do this allready for other
reasons that would be a bit over the top for only an 'active users' script.
--
Rik Wasmus
luiheidsgoeroe [ Di, 22 April 2008 21:25 ] [ ID #1947873 ]

Re: how to count logged users in php

On 22 Apr, 20:25, "Rik Wasmus" <luiheidsgoe... [at] hotmail.com> wrote:
> On Tue, 22 Apr 2008 21:14:13 +0200, <snowi... [at] gmail.com> wrote:
> > On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
> >> On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> >> > Hi all,
> >> > any way to count the number of users i have logged into my site?
> >> > any help/code appreciated,
> >> > craig
>
> >> Do you actually have people authenticating with usernames/passwords,
> >> or are you just looking to see how many people (unique users) have hit
> >> your site?
>
> > I have them logging in first, set by a session, so I just want to say
> > 'There are X users logged in' and then list the usernames.
>
> 1) Preferably use a database, have a table active_users
> 2) On each request with a session & logged in user, either insert a record
> with the user-id with a timestamp (or datetime) field, with the current
> time, or update an allready existing record with that information (if
> MySQL: ON DUPLICATE KEY UPDATE saves a lot of hassle).
> 3) On checking for active users, remove all entries from the active_users
> table with updated more than X minutes ago (X is your choice).
> 4) Display the list in active users.
>
> 1-3 are even easier (and more reliable) if you've taken to storing
> sessions in the database with a custom handler using
> session_set_save_handler(), but if you don't do this allready for other
> reasons that would be a bit over the top for only an 'active users' script.
> --
> Rik Wasmus

thanks for that

not sure how to write that though,.... :-(
snowinfo [ Di, 22 April 2008 21:35 ] [ ID #1947875 ]

Re: how to count logged users in php

On 22 abr, 16:14, snowi... [at] gmail.com wrote:
> On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
>
> > On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> > > Hi all,
> > > any way to count the number of users i have logged into my site?
> > > any help/code appreciated,
> > > craig
>
> > Do you actually have people authenticating with usernames/passwords,
> > or are you just looking to see how many people (unique users) have hit
> > your site?
>
> I have them logging in first, set by a session, so I just want to say
> 'There are X users logged in' and then list the usernames.
>
> That kinda thing
>
> Cheers

i'm just thinking
you should add a field in the users table with the "last activity"
timestamp, each time the user clicks on a link you will update this
field.
Then you can establish a period of time that you consider the user
online and doing a simple select with that criteria you are going to
get the number of users online

hope it was helpfull
Claudio Corlatti [ Di, 22 April 2008 21:36 ] [ ID #1947876 ]

Re: how to count logged users in php

On 22 abr, 16:14, snowi... [at] gmail.com wrote:
> On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
>
> > On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> > > Hi all,
> > > any way to count the number of users i have logged into my site?
> > > any help/code appreciated,
> > > craig
>
> > Do you actually have people authenticating with usernames/passwords,
> > or are you just looking to see how many people (unique users) have hit
> > your site?
>
> I have them logging in first, set by a session, so I just want to say
> 'There are X users logged in' and then list the usernames.
>
> That kinda thing
>
> Cheers

i'm just thinking
you should add a field in the users table with the "last activity"
timestamp, each time the user clicks on a link you will update this
field.
Then you can establish a period of time that you consider the user
online and doing a simple select with that criteria you are going to
get the number of users online

hope it was helpfull
Claudio Corlatti [ Di, 22 April 2008 21:37 ] [ ID #1947877 ]

Re: how to count logged users in php

On 22 Apr, 20:37, Claudio Corlatti <corla... [at] gmail.com> wrote:
> On 22 abr, 16:14, snowi... [at] gmail.com wrote:
>
>
>
> > On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
>
> > > On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> > > > Hi all,
> > > > any way to count the number of users i have logged into my site?
> > > > any help/code appreciated,
> > > > craig
>
> > > Do you actually have people authenticating with usernames/passwords,
> > > or are you just looking to see how many people (unique users) have hit
> > > your site?
>
> > I have them logging in first, set by a session, so I just want to say
> > 'There are X users logged in' and then list the usernames.
>
> > That kinda thing
>
> > Cheers
>
> i'm just thinking
> you should add a field in the users table with the "last activity"
> timestamp, each time the user clicks on a link you will update this
> field.
> Then you can establish a period of time that you consider the user
> online and doing a simple select with that criteria you are going to
> get the number of users online
>
> hope it was helpfull

Thanks for the comments, but i'm not that good in php yet.
I can read more than i can write,

Anyone got a good tutorial or code i can use?

many Thanks
Crai
snowinfo [ Di, 22 April 2008 21:50 ] [ ID #1947879 ]

Re: how to count logged users in php

On 22 abr, 16:50, snowi... [at] gmail.com wrote:
> On 22 Apr, 20:37, Claudio Corlatti <corla... [at] gmail.com> wrote:
>
>
>
> > On 22 abr, 16:14, snowi... [at] gmail.com wrote:
>
> > > On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
>
> > > > On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> > > > > Hi all,
> > > > > any way to count the number of users i have logged into my site?
> > > > > any help/code appreciated,
> > > > > craig
>
> > > > Do you actually have people authenticating with usernames/passwords,
> > > > or are you just looking to see how many people (unique users) have hit
> > > > your site?
>
> > > I have them logging in first, set by a session, so I just want to say
> > > 'There are X users logged in' and then list the usernames.
>
> > > That kinda thing
>
> > > Cheers
>
> > i'm just thinking
> > you should add a field in the users table with the "last activity"
> > timestamp, each time the user clicks on a link you will update this
> > field.
> > Then you can establish a period of time that you consider the user
> > online and doing a simple select with that criteria you are going to
> > get the number of users online
>
> > hope it was helpfull
>
> Thanks for the comments, but i'm not that good in php yet.
> I can read more than i can write,
>
> Anyone got a good tutorial or code i can use?
>
> many Thanks
> Crai

oh i'm sorry, i didn't see your previous reply
might this http://elouai.com/users.php will help you
it isn't for logged users, it counts users for ip, so maybe you have
to modify some things to adapt to your page

*sorry about my english ;O)
Claudio Corlatti [ Di, 22 April 2008 22:03 ] [ ID #1947881 ]

Re: how to count logged users in php

On 22 abr, 16:50, snowi... [at] gmail.com wrote:
> On 22 Apr, 20:37, Claudio Corlatti <corla... [at] gmail.com> wrote:
>
>
>
> > On 22 abr, 16:14, snowi... [at] gmail.com wrote:
>
> > > On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
>
> > > > On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> > > > > Hi all,
> > > > > any way to count the number of users i have logged into my site?
> > > > > any help/code appreciated,
> > > > > craig
>
> > > > Do you actually have people authenticating with usernames/passwords,
> > > > or are you just looking to see how many people (unique users) have hit
> > > > your site?
>
> > > I have them logging in first, set by a session, so I just want to say
> > > 'There are X users logged in' and then list the usernames.
>
> > > That kinda thing
>
> > > Cheers
>
> > i'm just thinking
> > you should add a field in the users table with the "last activity"
> > timestamp, each time the user clicks on a link you will update this
> > field.
> > Then you can establish a period of time that you consider the user
> > online and doing a simple select with that criteria you are going to
> > get the number of users online
>
> > hope it was helpfull
>
> Thanks for the comments, but i'm not that good in php yet.
> I can read more than i can write,
>
> Anyone got a good tutorial or code i can use?
>
> many Thanks
> Crai

oh i'm sorry, i didn't see your previous reply
might this http://elouai.com/users.php will help you
it isn't for logged users, it counts users for ip, so maybe you have
to modify some things to adapt to your page

*sorry about my english ;O)
Claudio Corlatti [ Di, 22 April 2008 22:05 ] [ ID #1947882 ]

Re: how to count logged users in php

On 22 abr, 16:14, snowi... [at] gmail.com wrote:
> On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
>
> > On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> > > Hi all,
> > > any way to count the number of users i have logged into my site?
> > > any help/code appreciated,
> > > craig
>
> > Do you actually have people authenticating with usernames/passwords,
> > or are you just looking to see how many people (unique users) have hit
> > your site?
>
> I have them logging in first, set by a session, so I just want to say
> 'There are X users logged in' and then list the usernames.
>
> That kinda thing
>
> Cheers

i'm just thinking
you should add a field in the users table with the "last activity"
timestamp, each time the user clicks on a link you will update this
field.
Then you can establish a period of time that you consider the user
online and doing a simple select with that criteria you are going to
get the number of users online

hope it was helpfull
Claudio Corlatti [ Di, 22 April 2008 22:06 ] [ ID #1947883 ]

Re: how to count logged users in php

i've found another one http://www.somecoders.com/2006/03/online-users/
Claudio Corlatti [ Di, 22 April 2008 22:13 ] [ ID #1947885 ]

Re: how to count logged users in php

On 22 Apr, 20:25, "Rik Wasmus" <luiheidsgoe... [at] hotmail.com> wrote:
> On Tue, 22 Apr 2008 21:14:13 +0200, <snowi... [at] gmail.com> wrote:
> > On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
> >> On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>
> >> > Hi all,
> >> > any way to count the number of users i have logged into my site?
> >> > any help/code appreciated,
> >> > craig
>
> >> Do you actually have people authenticating with usernames/passwords,
> >> or are you just looking to see how many people (unique users) have hit
> >> your site?
>
> > I have them logging in first, set by a session, so I just want to say
> > 'There are X users logged in' and then list the usernames.
>
> 1) Preferably use a database, have a table active_users
> 2) On each request with a session & logged in user, either insert a record
> with the user-id with a timestamp (or datetime) field, with the current
> time, or update an allready existing record with that information (if
> MySQL: ON DUPLICATE KEY UPDATE saves a lot of hassle).
> 3) On checking for active users, remove all entries from the active_users
> table with updated more than X minutes ago (X is your choice).
> 4) Display the list in active users.
>
> 1-3 are even easier (and more reliable) if you've taken to storing
> sessions in the database with a custom handler using
> session_set_save_handler(), but if you don't do this allready for other
> reasons that would be a bit over the top for only an 'active users' script.
> --
> Rik Wasmus

.....or just use a database bound session handler and reverse-engineer
how to get a count of sessions.

C.
colin.mckinnon [ Mi, 23 April 2008 14:00 ] [ ID #1948719 ]

Re: how to count logged users in php

On Wed, 23 Apr 2008 14:00:17 +0200, C. (http://symcbean.blogspot.com/)
<colin.mckinnon [at] gmail.com> wrote:

> On 22 Apr, 20:25, "Rik Wasmus" <luiheidsgoe... [at] hotmail.com> wrote:
>> On Tue, 22 Apr 2008 21:14:13 +0200, <snowi... [at] gmail.com> wrote:
>> > On 22 Apr, 20:09, venti <timgreg... [at] shieldinvestmentgroup.com> wrote:
>> >> On Apr 22, 3:05 pm, snowi... [at] gmail.com wrote:
>>
>> >> > Hi all,
>> >> > any way to count the number of users i have logged into my site?
>> >> > any help/code appreciated,
>> >> > craig
>>
>> >> Do you actually have people authenticating with usernames/passwords,
>> >> or are you just looking to see how many people (unique users) have
>> hit
>> >> your site?
>>
>> > I have them logging in first, set by a session, so I just want to say
>> > 'There are X users logged in' and then list the usernames.
>>
>> 1) Preferably use a database, have a table active_users
>> 2) On each request with a session & logged in user, either insert a
>> record
>> with the user-id with a timestamp (or datetime) field, with the current
>> time, or update an allready existing record with that information (if
>> MySQL: ON DUPLICATE KEY UPDATE saves a lot of hassle).
>> 3) On checking for active users, remove all entries from the
>> active_users
>> table with updated more than X minutes ago (X is your choice).
>> 4) Display the list in active users.
>>
>> 1-3 are even easier (and more reliable) if you've taken to storing
>> sessions in the database with a custom handler using
>> session_set_save_handler(), but if you don't do this allready for other
>> reasons that would be a bit over the top for only an 'active users'
>> script.
>....or just use a database bound session handler and reverse-engineer
> how to get a count of sessions.

Which is exactly what I said with 1-3 being simpler when storing the
sessions in a database...
--
Rik Wasmus
luiheidsgoeroe [ Mi, 23 April 2008 14:04 ] [ ID #1948721 ]
PHP » comp.lang.php » how to count logged users in php

Vorheriges Thema: Sessions not working in windows vista
Nächstes Thema: WSDL / SOAP function namespaces