Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts

    How to detect online/offline status

    I hope to find any one could help me in knowing a way to detect the online/offline status of the users,I spent much time in it and I didn't reach the goal.

  • #2
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    There are different ways.

    You could either make a column in the database called "status" which changes from online to offline and vise versa automatically.

    The way you could do that is to create a column called timestamp. And you probably have a config file - just update the user's timestamp and update the database.

    Something like
    PHP Code:
    $time time() + 600;
    $update mysql_query("UPDATE `accounts` SET `timestamp` = '".$time."'") or die(mysql_error());

    $setonline mysql_query("UPDATE `accounts` SET `status` = 'online' WHERE `timestamp` > '".time()."'") or die(mysql_error()); 
    Well, that was just an idea to get you started.

  • Users who have thanked [vengeance] for this post:

    Mido™ (09-13-2009)

  • #3
    Regular Coder
    Join Date
    Apr 2009
    Location
    somewhere over the rainbow
    Posts
    105
    Thanks
    2
    Thanked 14 Times in 14 Posts
    it easy.
    you need to manage a list (.txt\mySql) that contain the time the user last view the web page and to show the active users you request from the db all the active users within the last 5 minutes.

    e.g
    name | ip | last_active_time | start_time


    when a user enters `page.php` you add him to the list.
    + 2 another things that you need to do is to update the the user "last_active_time" if he is not a new user.
    + and to delete old users that are more than y minutes or you can log this to archive but remember to keep this table small.
    on the page you show all active users within the last x minutes.


    btw, there are meny free scripts just google for it damn!!
    :. -= | Eran | =- .:
    __________________

  • Users who have thanked Eran for this post:

    Mido™ (09-13-2009)

  • #4
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Store the sessions in the database:
    http://www.developertutorials.com/tu...711/page1.html
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    Mido™ (09-13-2009)

  • #5
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by [vengeance] View Post
    There are different ways.

    You could either make a column in the database called "status" which changes from online to offline and vise versa automatically.

    The way you could do that is to create a column called timestamp. And you probably have a config file - just update the user's timestamp and update the database.

    Something like
    PHP Code:
    $time time() + 600;
    $update mysql_query("UPDATE `accounts` SET `timestamp` = '".$time."'") or die(mysql_error());

    $setonline mysql_query("UPDATE `accounts` SET `status` = 'online' WHERE `timestamp` > '".time()."'") or die(mysql_error()); 
    Well, that was just an idea to get you started.
    I don't have a config file,also are you mean I should add a column in the users table or making a new table for this issue?

  • #6
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Eran View Post
    it easy.
    you need to manage a list (.txt\mySql) that contain the time the user last view the web page and to show the active users you request from the db all the active users within the last 5 minutes.

    e.g
    name | ip | last_active_time | start_time


    when a user enters `page.php` you add him to the list.
    + 2 another things that you need to do is to update the the user "last_active_time" if he is not a new user.
    + and to delete old users that are more than y minutes or you can log this to archive but remember to keep this table small.
    on the page you show all active users within the last x minutes.


    btw, there are meny free scripts just google for it damn!!
    so how I can know or find the active users and which if this user is active or not?

  • #7
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Zangeel View Post
    Store the sessions in the database:
    http://www.developertutorials.com/tu...711/page1.html
    thanks but this site don't show how I can use this way in my problem.

  • #8
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    Well, there are different ways, really. And I'm sure you'll find something on Google.

    But the example I showed was how I made mine. I have a config file, which is included on the top of every page I have. That means the config file is loaded upon each refresh.

    So if you run a script that posts the current time + 600 seconds (10 minutes) into the database, you can grab the timestamps later and do a simple "if timestamp is greater than current time" to check who's online.

    PHP Code:
    $getOnline mysql_query("SELECT `username` FROM `accounts` WHERE `timestamp` > '".time()."'") or die(mysql_error());
    if(
    mysql_num_rows($getOnline) > 0){
    while(
    $online mysql_fetch_array($getOnline)){
    echo 
    $online['username']."<br />";
    }
    }else{
    echo 
    "No one online.";

    Hope you understand. I'm actually on the go, so I won't be replying from now on, but I'll get back to you later, if you need any further help.

  • #9
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    If you store user sessions in the database, you will know when a person signs on and signs off (i.e. find out of theyre online of offline)
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    Mido™ (09-13-2009)

  • #10
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Zangeel View Post
    If you store user sessions in the database, you will know when a person signs on and signs off (i.e. find out of theyre online of offline)
    the idea look suitable but if you can explain the first steps of this way it will be better.

  • #11
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    I added a new column and I make it value ="online" when the user log in and make it offline when he log off.
    the code work well if only the user log off by the log off button,if he just closed the page and leave the site he is still online!
    I need now just a way to detect if the user leaved my site or not.
    note: I use the session and when user click log off the session destroyed.

  • #12
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by Mido™ View Post
    the code work well if only the user log off by the log off button,if he just closed the page and leave the site he is still online!
    That is why I suggested creating a timestamp column and update the timestamp for each individual user. After that you can get all users with a time() - 600 (10 minutes - your choice) or more and set those users' status to offline.

  • Users who have thanked [vengeance] for this post:

    Mido™ (09-14-2009)

  • #13
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by [vengeance] View Post
    That is why I suggested creating a timestamp column and update the timestamp for each individual user. After that you can get all users with a time() - 600 (10 minutes - your choice) or more and set those users' status to offline.
    I'll try this way,but the problem now if the user log in from a hour and during this time he is in my site he will be from the offline users.

  • #14
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by Mido™ View Post
    I'll try this way,but the problem now if the user log in from a hour and during this time he is in my site he will be from the offline users.
    I don't quite understand what you mean?

    If you include a file on top of every page which runs a script, that updates the user's timestamp in the database, then he'll eventually go offline, if he's not active.

    However when/if he refreshes a page the script will be executed again with a new timestamp, and the status will change to 'online'.

  • Users who have thanked [vengeance] for this post:

    Mido™ (09-15-2009)

  • #15
    Regular Coder
    Join Date
    Aug 2009
    Location
    in .........
    Posts
    263
    Thanks
    183
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by [vengeance] View Post
    I don't quite understand what you mean?

    If you include a file on top of every page which runs a script, that updates the user's timestamp in the database, then he'll eventually go offline, if he's not active.

    However when/if he refreshes a page the script will be executed again with a new timestamp, and the status will change to 'online'.
    Thanks but if you can put the that script or the things that should added in it I would be very thanked o you.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •