Insert/Auto Delete Users Online

Started on the old forum in October 2010 · view the original in the archive · old links redirect here

#mfws #online #users

No replies · 928 views · started 16 years ago · 1 min read

kiss Senior · 294 posts #1
  1. See demo at the front page of Mfws.Ro
  2. Create a file, named online.dat and give permission 666
  3. Create a file, named online.php and give permission 644 online.php
<?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($fp, serialize($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";
?>
  1. Create a file, named index.php and insert this code after <body> index.php
include("online.php"); 

or

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

www.inbuzunar.mobi -Your mobile portal pocket

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close