Log in

View Full Version : How many people are viewing your site script.



Gangster
07-04-2008, 04:10 PM
Does anyone know a script that displays how many people are viewing this site. So like "There are 67 people viewing this site"

++REP

Bojangles
07-04-2008, 04:27 PM
Make a folder called whosonline. In the folder make a file called online.php, insert this code into it.


<?


$ip = $REMOTE_ADDR;
$time = time();
$minutes = 15;
$found = 0;
$users = 0;
$user = "";

$tmpdata = $DOCUMENT_ROOT."/whosonline/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 "$users are online
";
?>
Make another folder in the whoseonline folder and call it data. In that folder make a file called online.txt and put this in :

66.235.180.56|1116831431
Now whichever page you want it to display on insert this:

<? include"http://www.yoursite.com/whosonline/online.php";?>

NOTE: This isn't my script!

iUnknown
07-04-2008, 10:36 PM
This script wouldn't work if you don't do any CHMODing :) CHMOD the online.txt file to 777 :)

Want to hide these adverts? Register an account for free!