Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - Show the Number of Users Online
MISCELLANEOUS

Show the Number of Users Online
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2002-07-08

    Table of Contents:
  • Show the Number of Users Online
  • The Code

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Show the Number of Users Online - The Code


    (Page 2 of 2 )

    Finally, here is the PHP Code:

    <?php
    //fill in some basic info
    $server "localhost";
    $db_user "username";
    $db_pass "password";
    $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 &gt; ";
    }

    //delete values when they leave
    $delete mysql_db_query($database"DELETE FROM useronline WHERE timestamp&lt;$timeout");
    if(!(
    $delete)) {
        print 
    "Useronline Delete Failed &gt; ";
    }

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

    //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");
    }
    ?>

    Not too tough was it? Well thats it folks. I hope it works out for you and if it doesn't, email for help at webmaster@spoono.com and we'll try to help you out.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap