Alright, I'm having some trouble (haven't been here in awhile). I'm trying to make a 'Users Online' type thing.
I want guests and members to appear. Here's the code I have. I've been studying it for awhile. It outputs no errors, but I have a funny feeling it isn't fwriting any of the data.
$timeout and $userid are defined elsewhere, but they are there.
$timestamp = time();
$old = $timestamp - $timeout;
// time to bust out the users online file
$users_online = fopen("data/users_online.txt","a");
fwrite($users_online, "$timestamp|$REMOTE_ADDR|$PHP_SELF|$userid|");
fclose($users_online);
$read = file("data/users_online.txt", "r");
foreach ($read as $read_line)
{
$buffer = explode("|", $read_line);
$stamps[] = trim($buffer[0]);
$ip[] = trim($buffer[1]);
$phpself[] = trim($buffer[2]);
$uid[] = trim($buffer[3]);
}
$users_online = fopen ("data/users_online.txt", "w");
flock ($users_online,2);
for ($x = 0; $x < sizeof($ip); $x++)
{
if ($stamps[$x] > $old && $ip[$x] != $REMOTE_ADDR && $stamps[$x] != $timestamp)
fputs($users_online, "$stamps[$x]|$ip[$x]|$phpself[$x]|$uid[$x]|");
flock ($users_online,3);
fclose($users_online);
$read = file("data/users_online.txt","r");
foreach ($read as $read_line)
{
if(isset($read_line) && $read_line!="")
{
$buffer = explode("|", $read_line);
$stamps[] = trim($buffer[0]);
$ip[] = trim($buffer[1]);
$phpself[] = trim($buffer[2]);
$uid[] = trim($buffer[3]);
if($buffer[3] != "")
$uid2[] = trim($buffer[3]);
}
}
$total_online = sizeof(array_unique($ip));
if(isset($uid2)) $members_online = sizeof(array_unique($lname2)); else $members_online = 0;
if(isset($lname2)) $guests_online = sizeof(array_unique($ip)) - sizeof(array_unique($uid2));
else $guests_online = sizeof(array_unique($ip));
}
See, this is what happens. It displays 1 guest, 0 members no matter how many people are at the page. I think it's just displaying everyone as guest, but not writing that data to the file, which it should. So it only shows 1 guest.
I'm kinda brainlocked on this one. Anyone can help me?
BTW, users_online.txt is CHMODDED to 0777, so that isn't an issue.
Thanks,
Michael Szczygiel (xwin)