1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How To Show How Many People Are Online? - Help Appreciated!

Discussion in 'PHP' started by James12513, Oct 31, 2007.

  1. #1
    I have a website which currently shows how many people are online in the last 2 minutes.

    However if a person has the site open in his browser but say he leaves the pc to get a drink, after 2 minutes, he is shown as being offline. Basically, you have to be clicking around the site to be shown as online.

    Could someone please help me in this dilemma!

    If I refresh the page every 2 minutes, this would be very annoying for the user.
    I'm not sure if I can refresh a single image every 2 minutes? Not sure if this would work.

    + rep for anyone that can help :)
    SEMrush
     
    James12513, Oct 31, 2007 IP
    SEMrush
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You could insert a hidden iframe, and in this iframe is a page that refreshes every X amount of time. And this page updates the counter.

    Other than that, PHP cannot connect to the client and check if he's still online. And if you want to do it from the clients side to the server, you need either HTML or Javascript.
     
    nico_swd, Oct 31, 2007 IP
    James12513 likes this.
  3. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well technically they are not online anymore.. you must extend the time that it checks?
     
    bobb1589, Oct 31, 2007 IP
  4. James12513

    James12513 Well-Known Member

    Messages:
    1,149
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    138
    #4
    Thanks nico_swd, I'm going to try it out, seems pretty complicated though lol


    If they don't click any links of the site, after 2 minutes it will show them as being offline.

    Most of the time, people just go away for 5 minutes to get a drink or food, they would like to be shown as online. So other people can send the messages and talk to them.
     
    James12513, Oct 31, 2007 IP
  5. sp360

    sp360 Well-Known Member

    Messages:
    1,023
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    160
    #5
    sp360, Oct 31, 2007 IP
    James12513 likes this.
  6. phpl33t

    phpl33t Banned

    Messages:
    456
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I keep a lot of where users are going and when they hit a page, their browser info/ip address/timestamp are stored. So, I ask mysql who's timestamp is less than 10 minutes and I get a pretty good idea. To keep the log from being huge, cron prunes in once every 5 hours.
     
    phpl33t, Oct 31, 2007 IP
    James12513 likes this.
  7. 9450184

    9450184 Peon

    Messages:
    30
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You need to set your timeout to longer period, to 5 or 10 minutes.
    It should be somewhere in your script, in the section where it records all the people online. It is probably time in seconds (120 for 2 minutes), so, you simply need to change that time to the value you need. Use 300 for 5 minutes, or 600 for 10 minutes.

    Good luck!~
     
    9450184, Nov 2, 2007 IP
    James12513 likes this.
  8. picobello

    picobello Active Member

    Messages:
    572
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #8
    picobello, Nov 2, 2007 IP
    James12513 likes this.
  9. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #9
    KJeep track of the last active time in the database.

    To get the count just select records where the last active time is less than 2 minutes ago

    Hope this helps
     
    tonybogs, Nov 2, 2007 IP
    James12513 likes this.
  10. joshhrob

    joshhrob Member

    Messages:
    96
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    48
    #10
    This sounds like a job for AJAX. AJAX will send data to the backend server behind the scenes so your user doesn't have to refresh the page. I've used this for IM chat on my website, but it would be perfect for what you're doing. If you Google PHP and AJAX you'll find something easy.
     
    joshhrob, Nov 2, 2007 IP
    James12513 likes this.
  11. James12513

    James12513 Well-Known Member

    Messages:
    1,149
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    138
    #11
    Thanks joshhrob, I will try this out, never used AJAX before but from what I've heard its not that hard.
     
    James12513, Nov 3, 2007 IP