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.

User online offline status code

Discussion in 'PHP' started by Om ji Kesharwani, Oct 17, 2010.

  1. #1
    How to check the user is online or offline for my community script.
     
    Om ji Kesharwani, Oct 17, 2010 IP
  2. Sabbir

    Sabbir Banned

    Messages:
    210
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
  3. pro-php-developer

    pro-php-developer Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Should be some tricky thing in PHP.Like checking the session table or something like that :)
     
    pro-php-developer, Oct 17, 2010 IP
  4. kasun0777

    kasun0777 Well-Known Member

    Messages:
    355
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #4
    kasun0777, Oct 17, 2010 IP
  5. SamT

    SamT Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    HTTP is stateless, therefore it is hard to determine whether someone is "online" or "offline". This needs to be done with some sort of session tracking and a "last click" time in the user's or session's table. You can then query it to find when their last click was.
     
    SamT, Oct 17, 2010 IP
  6. pro-php-developer

    pro-php-developer Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yep Sam is right .You should have something to save the state of user.something like a session table.And u know I've a pretty no.f time
    Good luck
     
    pro-php-developer, Oct 18, 2010 IP
  7. krishmk

    krishmk Well-Known Member

    Messages:
    1,376
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Well the best bet would be store Active User sessions in DB and check active status directly from DB during each page load.
     
    krishmk, Oct 18, 2010 IP
  8. ramsarvan

    ramsarvan Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    Just put an extra field in your profile table ie, status . And when a user logins ,update the table with a status 'ON' in that field and when the user logsout similarly update that field to 'OFF'.

    So, to show online members just put a select query with condition 'where status='ON''

    It will do...
     
    ramsarvan, Oct 18, 2010 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    Hmm what happens when a user does not logout but closes the website (and goes to another...) would he/she still be 'online'?:rolleyes:
     
    danx10, Oct 18, 2010 IP
  10. Griggs117

    Griggs117 Active Member

    Messages:
    73
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    85
    #10
    Personally I think the best way would be to have a table for a user where each time a user accesses a page, the php page inserts NOW() into a date time field, and then to determine if they are logged in or not the php page would say if(time() - $lastaccess < 15 minute) then logged in is true. Note this isn't the actual code you'd need to use. If you'd like me to write a simple function like this, just pm me.
     
    Griggs117, Oct 18, 2010 IP
  11. silviuks

    silviuks Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    you can have a separate table with session id, user id, time.
    when someone access your site you can check: if there is no session, then insert session id, user id (or null if is anonymous) and time.
    if is already a session for that visitor, you update the time field.
    alter that you can delete all rows with a period of inactivity.
     
    silviuks, Oct 19, 2010 IP