View Full Version : Online User Counter


Online?
03-27-2005, 05:05 PM
I'm fairly new at php but know a fair bit, anyway i'm hopeing you can help me out a bit here. I own a script website that allows users to copy and paste codes onto there website and i'm currently trying to make a online user counter.

I have got the online user counter:

<?php
// Configuration
$dbhost = "xxxxx";
$dbuser = "xxxxx"; // MySQL Username
$dbpass = "xxxxx"; // MySQL Password
$dbname = "xxxxx"; // Database Name
$timeoutseconds = 1200; // length of session, 20 minutes is the standard

$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
$ip = substr($REMOTE_ADDR, 0, strrpos($REMOTE_ADDR,"."));

// Connect to MySQL Database
@mysql_connect($dbhost,$dbuser,$dbpass);
@mysql_select_db($dbname) or die("No db");

// Add this user to database
$loopcap = 0;
while ($loopcap<3 && @mysql_query("insert into useronline values('$timestamp','$ip','$PHP_SELF')"))
{ // in case of collision
$timestamp = $timestamp+$ip{0}; $loopcap++;
}

// Delete users that have been online for more then "$timeoutseconds" seconds
@mysql_query("delete from useronline where timestamp<$timeout");

// Select users online
$result = @mysql_query("select distinct ip from useronline");
$user = @mysql_num_rows($result);

mysql_free_result($result);
@mysql_close();

// Show all users online
if ($user==1) {echo $user.' User Online';} else {echo $user.' Users Oline';}
?>

And what I want to do is make it so that on my website www.freescripts.co.nr I can let members copy and paste a code;

<!-- Powered by FreeScripts.Co.Nr -->
<script language="javascript" src="http://www.scripts.galvanize-solutions.com/online.php?sitename=WWW.YOURSITE.COM"></script><!-- Powered by FreeScripts.Co.Nr -->

and replace www.yoursite.com with there site and it will show the number of users online on there site and not mine. Can you help me here!

Thanks in advance.

Online?
03-27-2005, 07:13 PM
I thought this was a support forum?? :help:

bejayel
03-27-2005, 10:48 PM
you dont have anything that makes the websites distinct. you are also going ot over flow the mysql database by setting up your code like that. You should be update table where, not insert into table. If you are not going to use update you are going to overflow the database in 2 seconds if 10 people with a busy website use yoru counter. That whole things looks like it needs to be revamped a little bit.

Online?
03-28-2005, 09:07 AM
Don't worry, I know what i'm doing.. I want to make an online user counter like www.hosted-scripts.com or www.online-users.info

bejayel
03-28-2005, 05:47 PM
Wow did i ever look at that the wrong way. I understand what it si doing now. so what part of the script isnt working? does it work for you on your own website?