Jump to content
xisto Community
Sign in to follow this  
dylan2xs

Users Online Looking for the best counter script

Recommended Posts

Hi people, I am wondering If do you know a good "users online" I know many remote hosted services for this but I am looking for a counter script to install in my own website, If possible a counter that displays my visitors information , like country or an image(flag) links where they come from etc. something like this: Webpage I would SO appreciate any help! because I want to give to my site a more professional and international look :blink:

Share this post


Link to post
Share on other sites

I don't know of any. Maybe look at the source of that website? I really like the idea and if somone knows the answer i might use it too.

Unfortunately it's a remote hosted script, so looking the sourse of that web doesn't help much.. but I think they are making some changes to the counter and the map ..I prefered the previous version but they are using flash now... and some features have just gone.. :) or not working correctly ..at least not in my website Edited by dylan2xs (see edit history)

Share this post


Link to post
Share on other sites

Here are some useful counter scripts they are easy to put together.

Basic Users online counter

 <?$remote = $_SERVER["REMOTE_ADDR"];$file = "usersonline.txt";$timeoutseconds = 60; //Tells how long the user is considered "on line"$timestamp = time();$timeout = ($timestamp-$timeoutseconds);$fp = fopen("$file", "a+");$write = $remote."||".$timestamp."\n";fwrite($fp, $write);fclose($fp);$online_array = array();$file_array = file($file);foreach($file_array as $newdata){list($ip, $time) = explode("||", $newdata);if($time >= $timeout){array_push($online_array, $ip);}}$online_array = array_unique($online_array);$online = count($online_array);if($online == "1"){echo "Users Online: $online";}else{echo "Users Online: $online";}?>

Display IP number

<?php echo $_SERVER["REMOTE_ADDR"]; ?>

Display browser
<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>

To display a users time when they go to a website you can use one of these set ups.

<?php$today0 = date('D F d Y g:i a');				// Wed May 07 2003 1:21 am $today1 = date('F j, Y, g:i a');				 // March 10, 2001, 5:16 pm$today2 = date('m.d.y');						 // 03.10.01$today3 = date('j, n, Y');					   // 10, 3, 2001$today4 = date('Ymd');						   // 20010310$today5 = date('h-i-s, j-m-y, it is w Day z');  // 05-16-17, 10-03-01, 1631 1618 6 Fripm01$today6 = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day.$today7 = date('D M j G:i:s T Y');			   // Sat Mar 10 15:16:08 MST 2001$today8 = date('H:m:s \m \i\s\ \m\o\n\t\h');	 // 17:03:17 m is month$today9 = date('H:i:s');						 // 17:16:17echo "$today1<BR>$today2<BR>$today3<BR>$today4<BR>$today5<BR>$today6<BR>$today7<BR>$today8<BR>$today9";?>  

good place to check out some scripts are at pixel2life.com to get a good idea how to set them up and what not.

Share this post


Link to post
Share on other sites

I had the same problem as you, so i will share this script with you.
It works great, so i hope you like it.

In phpMyAdmin, click on your database then click on SQL at the top. Type this(see code below) in the box and click 'Go':

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`))
Now just copy this code where you want the stats to appear:
*you could also save this as: online_users.php (or any name you want) and use: <?php include 'online_users.php'; ?> on the
place you want the stat to appear*.
<?php//online users$server = "YOUR HOST"; // usually localhost$db_user = "USERNAME"; $db_pass = "PASSWORD"; $database = "DATABASE"; $timeoutseconds = 300; // length of gaps in the count//get time$timestamp = time(); $timeout = $timestamp-$timeoutseconds; //connect to databasemysql_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 ""; } //delete values when they leave$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout"); if(!($delete)) { 	print ""; } //grab the results$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); if(!($result)) { 	print ""; } //number of rows = the number of people online$user = mysql_num_rows($result); if(!($user)) {print("ERROR: " . mysql_error() . "\n");}//spit out the resultsmysql_close(); print("$user"); ?>

I hope this is what you where looking for.

Good luck

Share this post


Link to post
Share on other sites

Here are some useful counter scripts they are easy to put together.
Basic Users online counter

<?$remote = $_SERVER["REMOTE_ADDR"];$file = "usersonline.txt";$timeoutseconds = 60; //Tells how long the user is considered "on line"$timestamp = time();$timeout = ($timestamp-$timeoutseconds);$fp = fopen("$file", "a+");$write = $remote."||".$timestamp."\n";fwrite($fp, $write);fclose($fp);$online_array = array();$file_array = file($file);foreach($file_array as $newdata){list($ip, $time) = explode("||", $newdata);if($time >= $timeout){array_push($online_array, $ip);}}$online_array = array_unique($online_array);$online = count($online_array);if($online == "1"){echo "Users Online: $online";}else{echo "Users Online: $online";}?>

Display IP number

<?php echo $_SERVER["REMOTE_ADDR"]; ?>

Display browser
<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>

To display a users time when they go to a website you can use one of these set ups.

<?php$today0 = date('D F d Y g:i a');				// Wed May 07 2003 1:21 am $today1 = date('F j, Y, g:i a');				 // March 10, 2001, 5:16 pm$today2 = date('m.d.y');						 // 03.10.01$today3 = date('j, n, Y');					   // 10, 3, 2001$today4 = date('Ymd');						   // 20010310$today5 = date('h-i-s, j-m-y, it is w Day z');  // 05-16-17, 10-03-01, 1631 1618 6 Fripm01$today6 = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day.$today7 = date('D M j G:i:s T Y');			   // Sat Mar 10 15:16:08 MST 2001$today8 = date('H:m:s \m \i\s\ \m\o\n\t\h');	 // 17:03:17 m is month$today9 = date('H:i:s');						 // 17:16:17echo "$today1<BR>$today2<BR>$today3<BR>$today4<BR>$today5<BR>$today6<BR>$today7<BR>$today8<BR>$today9";?>

good place to check out some scripts are at pixel2life.com to get a good idea how to set them up and what not.


Tjeck http://www.chart.dk/ or try a CMS system called: PHP-fusion, its very good, I have a site wirt PHP-fusion (http://forums.xisto.com/no_longer_exists/)

Share this post


Link to post
Share on other sites

echo $usercount; - displays users.


The following code must go at the very top of your page before any HTML is sent to the browser. To call the function and assign the value to a variable, you simple use this line:

$usercount = getUsersOnline();


<?phpsession_start();function getUsersOnline() {   $count = 0;   $handle = opendir(session_save_path());   if ($handle == false) return -1;   while (($file = readdir($handle)) != false) {	   if (ereg("^sess", $file)) $count++;   }   closedir($handle);   return $count;}?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.