Number of People on a Page

Open up your notepad and save the current BLANK document as usersonline.txt (do not put anything in this document) - click edit->save as and place it in a folder where you can upload it later.

Close that document.

Open up notepad again and add the following script:

Code:

<?
  $remote = $_SERVER["REMOTE_ADDR"];
  $file = "usersonline.txt";
  $timeoutseconds = 60; //how long the user stays on, before classed offline
  $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";
  }
  ?>

Save this one as usersonline.php (it’s not the same as the above one. both have different file extensions, so don’t confuse one for the other, k.) Be sure you choose “All Files” option from the drop down box when saving so you can save it as a php file and not a text file! Also, make sure you save it where you saved the first one so you can upload it.

Now you’ll need to upload both documents in the same directory you have your website pages on that you’d like to display this handy script on. Once you have uploaded both files, chmod usersonline.txt to 777.

Now just copy the following piece of code into your website page where you’d like the number of users online to show up at:

Code:

<?
  include("usersonline.php");
  ?>
m121ban2





mp

Star Resell Our Services As Your Own
Basic Reseller
Pro Reseller
Reseller Login

register domain names
Domain Sales
.com $8.99 (Now-Sept)

dotme
NEW .ME
There’s a story inside each one of us, waiting to be told. Tell yours to the world with .ME -- the Top Level Domain that’s all about you!