Flash
  Home arrow Flash arrow Page 3 - Dynamic Flash Part 1: Counting Users Onlin...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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? 
FLASH

Dynamic Flash Part 1: Counting Users Online
By: Aaron Schaap
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2002-08-16

    Table of Contents:
  • Dynamic Flash Part 1: Counting Users Online
  • The Basics Of Dynamic Flash
  • Whose Online Using Flash
  • Whose Online Using Flash (contd.)
  • Conclusion

  • 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


    Dynamic Flash Part 1: Counting Users Online - Whose Online Using Flash


    (Page 3 of 5 )

    You may have remembered a while back when we published an article entitled 'Finding How Many Users Are On Your Site With PHP'. We will be modifying this code to suit our needs.

    Basically, when the code runs it will check to see if an entry for your I.P. address is already in the database and add an entry if it's not. It then counts how many distinct users (based on their I.P. address) have been on your site within the last 20 mins and spits that number out.

    This time, we will start with our PHP script and MySQL database. Fire up the MySQL console window and create a database called usersOnline:

    create database usersOnline;
    use usersOnline;


    Add a table to the database with the following query:

    create table usersOnline
    (
    id int auto_increment not null,
    userIP varchar(20) not null,
    dateAdded timestamp,
    primary key(id),
    unique id(id)
    );


    This will enable us to track our users. Next, create a new PHP file called count.php. Add the following code to count.php:

    <?php

    $dbServer = "localhost";
    $dbName = "usersOnline";
    $dbUser = "root";
    $dbpass = "";

    //add user to database
    global $HTTP_SERVER_VARS;

    define("SESSION_LENGTH", 20);

    $userIP = $HTTP_SERVER_VARS["REMOTE_ADDR"];

    $sConn = @mysql_connect($dbServer, $dbUser, $dbPass);

    $dbConn = @mysql_select_db($dbName, $sConn);

    $timeMax = time() - (60 * SESSION_LENGTH);
    $result = @mysql_query("select count(*) from usersOnline where unix_timestamp(dateAdded) >= '$timeMax' and userIP = '$userIP'");

    $recordExists = mysql_result($result, 0, 0) > 0 ? true : false;

    if(!$recordExists)
    {
    // Add a record for this user
    @mysql_query("insert into usersOnline(userIP) values('$userIP')");
    }

    //count users online

    $result = mysql_query("select count(*) from usersOnline where unix_timestamp(dateAdded) >= '$timeMax'");

    $usersOnline = mysql_result($result, 0, 0);

    //create our flash variable

    echo 'Count=' . $usersOnline;

    ?>


    Place it on your server in a folder called count. When run, the script will output something like this:

    Count=1

    More Flash Articles
    More By Aaron Schaap


     

    FLASH ARTICLES

    - Critical Flash Vulnerability Heats Up the Web
    - More on Nonpersistent Client-Side Remote Sha...
    - Nonpersistent Client-Side Remote Shared Obje...
    - Using the Decorator Pattern for a Real Web S...
    - Using Concrete Decorator Classes
    - Delving More Deeply into the Decorator Patte...
    - The Decorator Pattern in Action
    - A Simple Decorator Pattern Example
    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







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