marshy28
04-11-2003, 12:56 PM
Online Users
Message A few weeks ago on my website I had the number of online users showing up and everything worked fine but upon returning from hoilday I find that it has stopped working but i dont know why because I didnt do nothing.
I will post the code and .php file can anybody help with this
code line within my index page:
<?php include"/files/home1/douza/barrys/online/online.php";?>
.php (online.php):
<?
$ip = $REMOTE_ADDR;
$time = time();
$minutes = 15;
$found = 0;
$users = 0;
$user = "";
$tmpdata = $_SERVER['DOCUMENT_ROOT']."/files/home1/douza/barrys/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");
$users = $users + 1;
}
}
if ($found == 0)
{
fputs($f,"$ip|$time\n");
$users = $users + 1;
}
fclose ($f);
print "<strong><font face=Comic Sans Ms color=red>Online Visitors: $users</font></strong>";
?>
--
Best Regards,
Phil Marsh
email@douza.co.uk
Message A few weeks ago on my website I had the number of online users showing up and everything worked fine but upon returning from hoilday I find that it has stopped working but i dont know why because I didnt do nothing.
I will post the code and .php file can anybody help with this
code line within my index page:
<?php include"/files/home1/douza/barrys/online/online.php";?>
.php (online.php):
<?
$ip = $REMOTE_ADDR;
$time = time();
$minutes = 15;
$found = 0;
$users = 0;
$user = "";
$tmpdata = $_SERVER['DOCUMENT_ROOT']."/files/home1/douza/barrys/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");
$users = $users + 1;
}
}
if ($found == 0)
{
fputs($f,"$ip|$time\n");
$users = $users + 1;
}
fclose ($f);
print "<strong><font face=Comic Sans Ms color=red>Online Visitors: $users</font></strong>";
?>
--
Best Regards,
Phil Marsh
email@douza.co.uk