users online

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

users online

Post by shiznatix »

what would be the best way of doing a users online were it tells how many people are currently viewing the website? i dont want to do it with counting session id's so is there another way?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

1. Each page view
          a. check if session id is present in database
                       i) if exists
                             a. update row with current time
                      ii) if does not exist
                             a. create a new row with current time and session id
          b. check if any rows have expired time (compare current time with time in database)
                       i) if exists
                             a. delete the row
          c. SELECT COUNT (`id`) FROM `usersonline`
Something along these lines..
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Phenom:
shiznatix wrote: i dont want to do it with counting session id's so is there another way?
;)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

the OP could count in has access.log how many times the page has been requested the last 5 minutes and then say that all those requests where someone visiting that page...

but sessions are a mechanism that allow to work-around the fact that http is stateless.. i don't see any good reason not to use it....
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ya but when u use sessions they could goto the website, then without closing the browser goto another website and the session would still exist...rite?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

eventually, the session gets destroyed. You shouldn't have to worry about that.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

so there is no way to have a 100% acurate count of the amount of ppl viewing my website at any givin time?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

as i've said before...... check your access.log for that.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

LiLpunkSkateR wrote:Phenom:
shiznatix wrote: i dont want to do it with counting session id's so is there another way?
;)
we all have these moments...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

even with checking the access log, you only get a snapshot of how many requests have been done. Not how many are actually looking at the page. If you want to know definitively you need to require a "real-time" connection. This means Java, or a custom built application. At any rate, there is always a margin of error.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

poopy o well thanks for the help
Post Reply