How to display the users that are online?

Discussion in 'PHP' started by Kyriakos, Oct 7, 2009.

  1. #1
    hi,

    i want to display the users that are online in my web-site (not the number of users but their nicknames. like this forum is displaying the online users in the bottom.). do you have any idea how to do that?
     
    Kyriakos, Oct 7, 2009 IP
  2. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #2
    This could be done in a login.php page and a logout.php page and in mysql.

    so you would need to have a table with username password and whatever else you have but as another field you could create a field called logged and in that field it would say either "true" or "false"

    so when the user logs in in runs a mysql Insert into the table where username = whateverusername and it would place "true" into the field of logged

    and when user logs out it would do the same but place "false" into the field

    and then create a page called logged.php
    and you would run a mysql comand something like this:
    Select $username from table where logged == true

    Im not good with the exact mysql commands but you ge the basics of what I mean if not just PM me and I can work with you on getting this script to work

    -John
     
    jpinheiro, Oct 7, 2009 IP
  3. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    you have a nice idea but the problem is that the users are just closing the page. they don't click the "Logout" link. i want a script that can change the status of the logged in field from "true" to "false" in a inactive period of 20 minutes.
     
    Kyriakos, Oct 7, 2009 IP
  4. KEEP IT REAL

    KEEP IT REAL Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just set the time for how long cookie should remain active
    something like this setcookie($name, $value, time()+3600); //expire in 1 hour
     
    KEEP IT REAL, Oct 8, 2009 IP
  5. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    i want to delete the record from database after an inactive period of 20 minutes. not to expire a cookie.
     
    Kyriakos, Oct 8, 2009 IP
  6. KEEP IT REAL

    KEEP IT REAL Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You need to track it throught cookies not mysql lol...
    You dont want to load mysql with this
     
    KEEP IT REAL, Oct 8, 2009 IP
  7. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The way I did it on one of my sites was with AJAX: you call your PHP script with a Javascript function every 30 seconds (for example), and the script gets the current user ID and sets it as "online" in the DB with the current timestamp. The same script also sets as "offline" (or just deletes them from the "online" table) users with a timestamp older than 30 seconds (or a minute)
     
    picouli, Oct 8, 2009 IP
  8. nubpro

    nubpro Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Okay Thanks.
     
    nubpro, Aug 28, 2011 IP