Results 1 to 2 of 2

Thread: Display online users

Hybrid View

  1. #1
    Frenzied Member
    Join Date
    Jul 04
    Posts
    1,076

    Display online users

    this code shows the top 5 users

    how do i get it to show the users that are currently online?

    PHP Code:
    <?php
    $connect 
    mysql_connect("","","") or die("Couldn't connect!");
    mysql_select_db("prkscouk_users") or die("Couldn't find database");

    $query mysql_query("SELECT * FROM users ORDER BY id DESC LIMIT 5");

    $numrows mysql_num_rows($query);

    if (
    $numrows 0){
          while (
    $row mysql_fetch_assoc($query))
        {
            
    $id $row['id'];
            
    $username $row['username'];
    $email $row['email'];
            echo 
    "<a href=mailto:$email>$username</a><br>";
        }
    }
    else
    {
         echo 
    "No users were found.";
    }
    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    Re: Display online users

    First, define "online".
    In other words, if I visit a page on your site, when do I stop being online? On this site, for example, it's about ten minutes after the last visit.

    To make this work, you need to store the last visit time against each user. When (an authenticated) user visits any page, update this field to the current time. To show all "online" users, select from the users table where the last visit time is less than your predetermined amount of time before the current time.

Posting Permissions

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