Miscellaneous
  Home arrow Miscellaneous arrow Page 2 - Show the Number of Users Online
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

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

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

       · I don't know but it seems to me that this doesn't teach you how to do this, it just...
     

    MISCELLANEOUS ARTICLES

    - Using PHP to Stream MP3 Files and Prevent Il...
    - 10 Must Have Firefox Improvements
    - All About OpenOffice 3.0
    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell
    - Data Streams and the UNIX Shell
    - Control Mechanisms of the UNIX Shell
    - Variables Within the UNIX Shell
    - The Shell and UNIX
    - In Detail: UNIX File Systems
    - Rights Management in UNIX
    - UNIX File Systems
    - The Terminal in UNIX
    - Operating Systems and UNIX





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek