Announcement

Collapse
No announcement yet.

Whos Online

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Whos Online

    Can some PHP expert tell me how to create a Whos Online Script Like Vbulletin. I got the users DB already. A simple one will do

  • #2
    (I'm not taking credit for this code){

    <?php
    //fill in some basic info
    $server = "localhost";
    $db_user = "user";
    $db_pass = "pass";
    $database = "users";
    $timeoutseconds = 300;

    //get the time
    $timestamp = time();
    $timeout = $timestamp-$timeoutseconds;

    //connect to database
    mysql_connect($server, $db_user, $db_pass);

    //insert the values
    $insert = mysql_db_query($database, "INSERT INTO useronline VALUES
    ('$timestamp','$REMOTE_ADDR','$PHP_SELF')");
    if(!($insert)) {
    print "Useronline Insert Failed > ";
    }

    //delete values when they leave
    $delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout");
    if(!($delete)) {
    print "Useronline Delete Failed > ";
    }

    //grab the results
    $result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'");
    if(!($result)) {
    print "Useronline Select Error > ";
    }

    //number of rows = the number of people online
    $user = mysql_num_rows($result);


    //spit out the results
    mysql_close();
    if($user == 1) {
    print("$user user online\n");
    } else {
    print("$user users online\n");
    }
    ?>




    And the table structure:

    CREATE TABLE useronline (
    timestamp int(15) DEFAULT '0' NOT NULL,
    ip varchar(40) NOT NULL,
    file varchar(100) NOT NULL,
    PRIMARY KEY (timestamp),
    KEY ip (ip),
    KEY file (file)
    );

    Comment


    • #3
      Thanks

      Comment


      • #4
        Thx also.

        Cleared up some other things for me
        Email: [email protected]
        Site: Under Construction

        Comment


        • #5
          You do realize the script itself is not enough, right?
          You also need to update the useronline table every time a page is viewed, just like vBulletin does with its sessions.php file.
          Chen Avinadav
          Better to remain silent and be thought a fool than to speak out and remove all doubt.

          גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

          Comment


          • #6
            Originally posted by FireFly
            You do realize the script itself is not enough, right?
            You also need to update the useronline table every time a page is viewed, just like vBulletin does with its sessions.php file.
            Yeap, I am not using the script. But the code and the syntax has cleared up some other problems i was having.
            Email: [email protected]
            Site: Under Construction

            Comment


            • #7
              can I use that on my HTML index page linking back into my vBulletin forum to show whoes on the forum ??
              Dez U

              VB4.2 Suite ClanRam
              VB4.2 Suite Refrigeration-Engineer
              VB4.2 Suite ScottishHD

              Comment


              • #8
                Originally posted by Dez_U
                can I use that on my HTML index page linking back into my vBulletin forum to show whoes on the forum ??
                means u want to put vb whosonline page onto ur main page. izzit?

                Comment

                widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                Working...
                X