<?php
$ip = $REMOTE_ADDR; // $REMOTE_ADDR gets the users ip address
$time = time(); // this adds the time of day to the script,,,
$minutes = 1; // the count of the minutes for how long
$found = 0; // how many users found, aka: ip address for start
$users = 0; // number of users determined for start
$user = ""; // users know already,,, aka: no users yet
if (!is_file("online.txt")) // text file used for figuring how man users online.
{
$s = fopen("online.txt","w"); //creates file if not one
fclose($s);
chmod("online.txt",0666); // chmod filt
}
$f = fopen("online.txt","r+"); // opens file
flock($f,2);
while (!feof($f))
{
$user[] = chop(fgets($f,65536));
}
fseek($f,0,SEEK_SET);
ftruncate($f,0);
foreach ($user as $line) // configures each user, no doubles
{
list($savedip,$savedtime) = split("\|",$line);
if ($savedip == $ip) {$savedtime = $time;$found = 1;}
if ($time < $savedtime + ($minutes * 60))
{
fputs($f,"$savedip|$savedtime\n");
$users = $users + 1;
}
}
if ($found == 0) // writes to file
{
fputs($f,"$ip|$time\n");
$users = $users + 1;
}
fclose ($f);
print 'Users Viewing Site : '.$users;
?>
this is a php script that writes to a text file for how many users are online. its more like how many guests are online, or how many users are at the site currently at the same time this script runs,,,
$ip = $REMOTE_ADDR; // $REMOTE_ADDR gets the users ip address
$time = time(); // this adds the time of day to the script,,,
$minutes = 1; // the count of the minutes for how long
$found = 0; // how many users found, aka: ip address for start
$users = 0; // number of users determined for start
$user = ""; // users know already,,, aka: no users yet
if (!is_file("online.txt")) // text file used for figuring how man users online.
{
$s = fopen("online.txt","w"); //creates file if not one
fclose($s);
chmod("online.txt",0666); // chmod filt
}
$f = fopen("online.txt","r+"); // opens file
flock($f,2);
while (!feof($f))
{
$user[] = chop(fgets($f,65536));
}
fseek($f,0,SEEK_SET);
ftruncate($f,0);
foreach ($user as $line) // configures each user, no doubles
{
list($savedip,$savedtime) = split("\|",$line);
if ($savedip == $ip) {$savedtime = $time;$found = 1;}
if ($time < $savedtime + ($minutes * 60))
{
fputs($f,"$savedip|$savedtime\n");
$users = $users + 1;
}
}
if ($found == 0) // writes to file
{
fputs($f,"$ip|$time\n");
$users = $users + 1;
}
fclose ($f);
print 'Users Viewing Site : '.$users;
?>
this is a php script that writes to a text file for how many users are online. its more like how many guests are online, or how many users are at the site currently at the same time this script runs,,,
