Jick
08-05-2003, 04:36 PM
I found this script which they say will tell you the current users online and also the users that have been on all day. Right now it's two seperate files. One called (online.php) and the other called (today.php). They each have a log file that they write their info to: (online.txt) and (today.txt). I'm pretty sure it's possible to merge these two scripts but still have them function the same way. I need help merging them please.
Here is (online.php):
<?PHP
$ip = $REMOTE_ADDR;
$time = time();
$minutes = 15;
$found = 0;
$usersnow = 0;
$user = "";
$tmpdata = $DOCUMENT_ROOT."/online/data";
if (!is_file("$tmpdata/online.txt"))
{
$s = fopen("$tmpdata/online.txt","w");
fclose($s);
chmod("$tmpdata/online.txt",0666);
}
$f = fopen("$tmpdata/online.txt","r+");
flock($f,2);
while (!feof($f))
{
$user[] = chop(fgets($f,65536));
}
fseek($f,0,SEEK_SET);
ftruncate($f,0);
foreach ($user as $line)
{
list($savedip,$savedtime) = split("\|",$line);
if ($savedip == $ip) {$savedtime = $time;$found = 1;}
if ($time < $savedtime + ($minutes * 60))
{
fputs($f,"$savedip|$savedtime\n");
$usersnow = $usersnow + 1;
}
}
if ($found == 0)
{
fputs($f,"$ip|$time\n");
$users = $usersnow + 1;
}
fclose ($f);
?>
And here is (today.php):
<?PHP
$ip = $REMOTE_ADDR;
$time = time();
$minutes = 60 * 24;
$found = 0;
$userstoday = 0;
$user = "";
$tmpdata = $DOCUMENT_ROOT."/online/data";
if (!is_file("$tmpdata/today.txt"))
{
$s = fopen("$tmpdata/today.txt","w");
fclose($s);
chmod("$tmpdata/today.txt",0666);
}
$f = fopen("$tmpdata/today.txt","r+");
flock($f,2);
while (!feof($f))
{
$user[] = chop(fgets($f,65536));
}
fseek($f,0,SEEK_SET);
ftruncate($f,0);
foreach ($user as $line)
{
list($savedip,$savedtime) = split("\|",$line);
if ($savedip == $ip) {$savedtime = $time;$found = 1;}
if ($time < $savedtime + ($minutes * 60))
{
fputs($f,"$savedip|$savedtime\n");
$userstoday = $userstoday + 1;
}
}
if ($found == 0)
{
fputs($f,"$ip|$time\n");
$users = $userstoday + 1;
}
fclose ($f);
?>
And here my (index.php) file that displays the info:
<?PHP include ("online.php"); ?>
<?PHP include ("today.php"); ?>
Visitors Online Now: <?PHP echo "$usersnow"; ?><br>
Visitors Online Today: <?PHP echo "$userstoday"; ?>
You can also preview it by going to: http://kd7pyo.infinitypages.com/online/.
Here is (online.php):
<?PHP
$ip = $REMOTE_ADDR;
$time = time();
$minutes = 15;
$found = 0;
$usersnow = 0;
$user = "";
$tmpdata = $DOCUMENT_ROOT."/online/data";
if (!is_file("$tmpdata/online.txt"))
{
$s = fopen("$tmpdata/online.txt","w");
fclose($s);
chmod("$tmpdata/online.txt",0666);
}
$f = fopen("$tmpdata/online.txt","r+");
flock($f,2);
while (!feof($f))
{
$user[] = chop(fgets($f,65536));
}
fseek($f,0,SEEK_SET);
ftruncate($f,0);
foreach ($user as $line)
{
list($savedip,$savedtime) = split("\|",$line);
if ($savedip == $ip) {$savedtime = $time;$found = 1;}
if ($time < $savedtime + ($minutes * 60))
{
fputs($f,"$savedip|$savedtime\n");
$usersnow = $usersnow + 1;
}
}
if ($found == 0)
{
fputs($f,"$ip|$time\n");
$users = $usersnow + 1;
}
fclose ($f);
?>
And here is (today.php):
<?PHP
$ip = $REMOTE_ADDR;
$time = time();
$minutes = 60 * 24;
$found = 0;
$userstoday = 0;
$user = "";
$tmpdata = $DOCUMENT_ROOT."/online/data";
if (!is_file("$tmpdata/today.txt"))
{
$s = fopen("$tmpdata/today.txt","w");
fclose($s);
chmod("$tmpdata/today.txt",0666);
}
$f = fopen("$tmpdata/today.txt","r+");
flock($f,2);
while (!feof($f))
{
$user[] = chop(fgets($f,65536));
}
fseek($f,0,SEEK_SET);
ftruncate($f,0);
foreach ($user as $line)
{
list($savedip,$savedtime) = split("\|",$line);
if ($savedip == $ip) {$savedtime = $time;$found = 1;}
if ($time < $savedtime + ($minutes * 60))
{
fputs($f,"$savedip|$savedtime\n");
$userstoday = $userstoday + 1;
}
}
if ($found == 0)
{
fputs($f,"$ip|$time\n");
$users = $userstoday + 1;
}
fclose ($f);
?>
And here my (index.php) file that displays the info:
<?PHP include ("online.php"); ?>
<?PHP include ("today.php"); ?>
Visitors Online Now: <?PHP echo "$usersnow"; ?><br>
Visitors Online Today: <?PHP echo "$userstoday"; ?>
You can also preview it by going to: http://kd7pyo.infinitypages.com/online/.