Home arrow Flash arrow Page 3 - Dynamic Flash Part 1: Counting Users Online
FLASH

Dynamic Flash Part 1: Counting Users Online


New to Flash? Come join Ben in this, the first of many weekly Flash articles, as he shows us how to use Flash and PHP to show a count of users on your web site.

Author Info:
By: Aaron Schaap
Rating: 4 stars4 stars4 stars4 stars4 stars / 10
August 16, 2002
TABLE OF CONTENTS:
  1. · Dynamic Flash Part 1: Counting Users Online
  2. · The Basics Of Dynamic Flash
  3. · Whose Online Using Flash
  4. · Whose Online Using Flash (contd.)
  5. · Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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
blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- 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

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials