Results 1 to 8 of 8

Thread: online users list

  1. #1
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default online users list

    I want to create list of online users with php... I have an idea to create mysql variable which saves numbers 0 or 1. when user logs i it will be rewritten to 1, when logs out to 0. And my list will show all users, who have 1 in their wariables.

    Maybe someone have better idea? Or can write me a script of my idea? Because i do too much mistakes. THANKS A LOT
    Last edited by auriaks; 11-12-2009 at 01:52 AM.

  2. #2
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    too difficult?

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    The way you proposed sounds like it should work and I can't see any other way of doing it, maybe using a text file... But just changing a variable from 0 to 1 should do the trick and it shouldn't be too hard to implement.

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    That's assuming your users always log out though. If they don't and just exit the browser then that number will begin to become high quickly. You could make up an activity table that sets their log in time and there activity time. If their activity time goes past some amount of time make their online number back to 0.

  5. #5
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    good idea to use time... thanks. maybe u can tell me some links with lessons of that?

  6. #6
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    session: (some lines)
    PHP Code:
     session_start();
            
    $_SESSION['nick'] = $_POST['nick'];
            
    $_SESSION['password'] = md5($_POST['password']);
            
    $_SESSION['authID'] = $r['id']; 
    online script:
    PHP Code:
    <?php 

    include('db_conn.php'); 

    session_start(); // begin session 

    if(isset($_SESSION['authID'])) { 
    $q mysql_query("SELECT * FROM reg_users WHERE Nick='$_SESSION[nick]'") or die(mysql_error()); 
    $r mysql_fetch_array$q ) or die(mysql_error()); 
    //atsiras
    $date date("Y-m-d");
    $count1 '1';
    $nick $_SESSION['nick'];
    mysql_query("UPDATE reg_users SET date = '$date' WHERE name = '$nick'");
    mysql_query("UPDATE reg_users SET count = '$count1' WHERE name = '$nick'");
    //atsiras-pabaiga

    } else { } 
    if(
    $_GET['act'] == 'logout') {
        echo 
    '<center><font color="Green">You\'re successfully logged out.</font></center>';
        
    session_unset();
        
    session_destroy(); // remove the entire session
        
    include('db_conn.php');
        
    $count2 '0';
        
    mysql_query("UPDATE reg_users SET count = '$count2' WHERE name = '$nick'");
    }
    ?>
    My number and date doesnt changes... maybe see where?? and how to add time there? THANKS

  7. #7
    Join Date
    Jul 2009
    Location
    Coquitlam BC Canada
    Posts
    46
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    Time? Just like date:
    PHP Code:
    <?php
    $i
    =date("Y-m-d H:i:s");//the default for php/mysql
    ?>
    Quote Originally Posted by auriaks View Post

    My number and date doesnt changes... maybe see where?? and how to add time there? THANKS
    Are you sure the mysql field format is date?

  8. #8
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    How i can use this time into my script? I thought about command which gives automatically (every 5 minutes) looks if user is logged...

Bookmarks

Posting Permissions

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