How many users online, PHP

Discussion in 'PHP' started by tomsign, Jul 19, 2010.

  1. #1
    Hi,

    anyone can tell me the way to display how many users are online the site in PHP
    without utilizing mysql ???





    Thank you friend :)
     
    tomsign, Jul 19, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    You'll need some sort of counting system so you either use a text file as a database table or you use mysql.

    effectively everytime someone opens a page you read the contents of the file, drop the lines that are "old" and add your new line and write to the file.

    The line might be datetime|ip address
    that way you know when the line is "old" and you know who accessed. Also gives you the option to remove old lines for the same IP so that 1 person with 5 tabs open only gets counted once.
     
    sarahk, Jul 19, 2010 IP
  3. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Start a session at the beginning of every page then use session_save_path() to see where the sessions are saved on the server and read all the access times of the files in that directory (they begin with 'sess'). Count all the files that have been accessed within the past 2 to 5 minutes.... this count will be how many users are currently browsing your site.
     
    Deacalion, Jul 19, 2010 IP
  4. ttyler333

    ttyler333 Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    ttyler333, Jul 21, 2010 IP
  5. dacash

    dacash Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I would utilize some PHP and Javascript. do a onload() and onbeforeunload() that sends data to php to save to file or db. That is how Google does it on their analytics system.
     
    dacash, Jul 21, 2010 IP
  6. ttyler333

    ttyler333 Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #6
    I just created a flash version to check :) its pretty active.. down the the last minute of when a user was online. Anyways its also a chatroom :)
     
    ttyler333, Jul 21, 2010 IP
  7. yohanip

    yohanip Well-Known Member

    Messages:
    350
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #7
    This is a neat trick :)
    anyway, any ideas when we implements dynamic sessions, i.e "session_regenerate_id" does the file name stays the same?
    thank you for your time :)
     
    yohanip, Jul 21, 2010 IP