FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

users online, using php and text file

 


spider
<?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,,,
simplyw00x
Way to post something you didn't write (or may have; you never said, yet this appears on several other websites), reputedly doesn't work and in the wrong forum to top it off. Smooth Rolling Eyes
spider
its a tutorial,, everything for everyone,,, doesnt matter who made it and where it came from,,, what matters is if they know something about, or how it works,, and i might add that it wasnt a very good tutorial either...
spider
and sorry, dont know why it doesnt work for you, works fine on my site... i have another that i use on another one of my sites i admin...
Kit
spider wrote:
and sorry, dont know why it doesnt work for you, works fine on my site... i have another that i use on another one of my sites i admin...


Double posting to top it all off? Just for the record the
Code:
awesome

Code brackets are great.

I'm off to test it if I get a chance but I scanned it and the code looked clean.. Are you sure it does not work?
Reply to topic    Frihost Forum Index -> Miscellaneous -> Tutorials

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.