Free Webmasters Resources, Webmaster Tools, CGI Scripts, Web Tutorials, Web Articles  

Click Here
Navigation
Home
Advertise
Webmaster Forums
Webmaster Resources
Webmaster Tools
Web Articles
Tutorials
Free Newsletter

Link To Us
Site Map
About Us
Search
Contact

Webmaster Resources
Resource Home
Submit Resource

Commerce
Free Services
Learning
Online Tools
Our Webmaster Tools
Promotion
Scripts
Software
Web Hosting
Website Design


Webmaster Tools
SEO Tools

- Meta Tag Generator
- Google Position Checker
- Keyword Density Analyzer
- Keyword Generator
- Link Popularity Checker
- Meta Tag Analyzer
- Search Index Report
- Search Engine Simulator
- Web Page Analyzer
- Yahoo Position Checker

HTML Tools

- Color Chart
- Color Converter
- Dreamweaver Code Cleaner
- Frontpage Code Cleaner
- HTML Entities List
- Web Page Size Checker

Domain Tools

- Domain Typo Generator
- Whois Lookup

Other Tools

- HTTP Headers Viewer
- IP Address


Free Newsletter
This is a private mailing list and will never be sold or given away for any reason. Newsletter sent out in HTML format.


First Name:


Email Address:




More Information
Archives


Poll
Where do you live?
Africa
North America
South America
Asia
Australia/Pacific
Europe
 

Results
Past Results


Site Search
Search this entire Website for articles, tutorials, reviews and other resources.


Adv. Search

Scripts & Programs
Submit Script

ASP Scripts
C and C++ Scripts
JavaScripts
Perl and CGI Scripts
PHP Scripts
Remotely Hosted


Web Articles
Submit Article

Coding
eZine Production
Marketing Tips
Online Business
Other Internet Articles
Search Engines
Web Design
Web Hosting


Tutorials
Submit Tutorial

ASP Tutorials
C and C++ Tutorials
ColdFusion Tutorials
DHTML Tutorials
Flash Tutorials
Graphic Tutorials
HTML Tutorials
JavaScript Tutorials
Perl Tutorials
PHP Tutorials
Web Design Tutorials
XML Tutorials


How Many Users Online?

Home Page :: Authors Login :: Author Signup :: Search :: More Articles

Home :: PHP/MySQL


About This Author :: Request Reprint :: Print Article :: Tell A Friend


How Many Users Online?
By Ben Sinclair
Contact Ben Sinclair


You can easily show how many users are online with PHP and MySQL!

The MySQL Part

First of all you will need to create a table in your MySQL Database:


CREATE TABLE `useronline` (
  `timestamp` int(15) NOT NULL default '0',
  `ip` varchar(40) NOT NULL default '',
  `file` varchar(100) NOT NULL default '',
  PRIMARY KEY  (`timestamp`),
  KEY `ip` (`ip`),
  KEY `file` (`file`)
) TYPE=MyISAM;



Showing The Users

You now need to create a file called useronline.php. Fill out the configuration with your own information:


<?
// -------------------------------------
//  Configuration
// -------------------------------------

$dbhost = "localhost";
$dbuser = "";&nbsp; // MySQL Username
$dbpass = "";&nbsp; // MySQL Password
$dbname&nbsp; = ""; // Database Name
$timeoutseconds&nbsp; = 300;&nbsp; &nbsp;// How long till it will remove the user from the database(In seconds)

// -------------------------------------

$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
// Connect to MySQL Database
mysql_connect($d_host,$dbuser,$dbpass);
@
mysql_select_db($dbname) or die("Unable to select database");
// Add this user to database
mysql_query("insert into useronline values('$timestamp','$REMOTE_ADDR','$PHP_SELF')") or die("<b>MySQL Error:</b> ".mysql_error());
// Dlete users that have been online for more then "$timeoutseconds" seconds
mysql_query("delete from useronline where timestamp<$timeout") or die("<b>MySQL Error:</b> ".mysql_error());
// Select users online
$result = mysql_query("select distinct ip from useronline") or die("<b>MySQL Error:</b> ".mysql_error());
$user = mysql_num_rows($result);
// Select users on this very page
$resulta = mysql_query("select distinct ip from useronline where file='$PHP_SELF'") or die("<b>MySQL Error:</b> ".mysql_error());
$usera = mysql_num_rows($resulta);
mysql_close();

// Show all users online
if ($user==1) {echo"$user user online!</font>";} else {echo"$user users online.";}
// Show users on this very page
if ($usera==1) {echo"<br>$user user viewing this page!</font>";} else {echo"$user users viewing this page.";}
?>



Now you need to include it on everypage:


<?php
include("useronline.php");
?>



That's everything!

Enjoy!

Discuss this in our Webmaster Forums

About The Author:
Ben Sinclair

Ben Sinclair is the Webmaster of Webmaster Resources 101(/)

Go To Top

This article has been read 7 times.


About This Author :: Request Reprint :: Print Article :: Tell A Friend



Advertising
Advertise your website here. View Advertising Information.

Google Ranking Tool
Search Engine OptimizationGet This Tool Free!

Home   Search   Contact   About Us  

Hot Resources
We have found some of the Hottest Resources around just for you! Check these out:
Search Engine Promotion
- Search engine specialist
- Over 200 clients worldwide
- SEO as low as $499
- Link Building for $150

More info...

Online Dating Script

aeDating 3.0 new version of famous dating software with free installation, lifetime upgrades and technical support. New templates, private photos, credits payment system, integrated with phpBB, banner system, new IM.

Visit resource

Search Engine Placement
Since 1997 StepForth has been a result and client oriented search engine optimization and placement company. Our SEO services are guaranteed and proven. Questions? Contact us: 1-877-385-5526

More info...

Best Web Hosting!
- LunarPages ($7.95)
- iPowerWeb ($7.95)
- Globat ($7.50)
- PowWeb ($7.77)

WebHosting $7.50/mo
$7.50/mo - 1000 MB Space, 40 GB Transfer, 24/7 Support, 99.9% Uptime, FREE Domain and FREE Setup.

More info...


Sponsors
Web Hosting
Web Hosting India
StartLogic
Web Hosting
Cheap Web Hosting

Search Engines
Search Engine Optimization SEO
NetVisits Web Directory
Search Engine Optimization

Webmaster Tools
Webmaster Resources

Software
MAS 90

Domain Names
Resell Domain Names and More!

Link Popularity
Reciprocal Link Exchange Directory
Link Building Campaigns

Great Deals
Cheap Flights
Cheap Car Rental
Cheap Mobile Phones
Plasma Televisions



Partners
Dreamweaver Web Templates
Motivational Memo
Website Advertising
Php Scripts
Cheap Web Hosting
Cheap Web Host
Free Webmaster Resources
Need CGI
Desro Webmaster Resources
Web-Mastery Web-Resources
Top 10 Hosts - PHP MySQL

Books
The Animators Survival Kit

The Animators Survival Kit


Dating Services Software

Contact Information

Powered by Outasight Enterprises Pty Ltd
PO Box 1218 Mudgeeraba QLD 4213 AUS
All content � Webmaster Resources 101, 2002-2004 unless otherwise stated.
Design by OE Design Hosted by Surf Speedy View our Privacy Policy
Page loaded in 1.907 secs.
4 users online.

The Hottest Reseller Program Going!