0. See demo at the front page of Mfws.Ro
1. Create a file, named online.dat and give permission 666
2. Create a file, named online.php and give permission 644
online.php
PHP Code:
<?php
$expire 
900//seconds
$dbfile "online.dat";
if(!
is_writable($dbfile))
{
die(
"Data file ".$dbfile." is not writable");
}
if(!
file_exists($dbfile))
{
die(
"Data file ".$dbfile." was not found");
}
function 
netip()
{
if(!empty(
$_SERVER["HTTP_CLIENT_IP"]))
{
$ip $_SERVER["HTTP_CLIENT_IP"];
}else if(!empty(
$_SERVER["HTTP_X_FORWARDED_FOR"]))
{
$ip $_SERVER["HTTP_X_FORWARDED_FOR"];
}else{
$ip $_SERVER["REMOTE_ADDR"];
}
return 
$ip;
}
function 
counter()
{
global 
$dbfile$expire;
$cur_ip netip();
$cur_time time();
$dbary_new = array();
$dbary unserialize(@file_get_contents($dbfile));
if(
is_array($dbary))
{
while(list(
$user_ip$user_time) = each($dbary))
{
if((
$user_ip != $cur_ip) && (($user_time $expire) > $cur_time))
{
$dbary_new[$user_ip] = $user_time;
}
}
}
$dbary_new[$cur_ip] = $cur_time;
$fp fopen($dbfile"w");
fputs($fpserialize($dbary_new));
fclose($fp);
$out sprintf("%02d"count($dbary_new));
return 
$out;
}
$online counter();
echo 
date("D, d.m.Y - H:i:s")."\n";
echo 
"<br/>\n";
echo 
"Now: <b>".$online."</b>,\n";
echo 
"You: <b>".netip()."</b>\n";
?>
3. Create a file, named index.php and insert this code after <body>
index.php
PHP Code:
include("online.php"); 
or
PHP Code:
<?php
include("online.php"); 
?>