number of visitors online
Posted: Thu Jan 17, 2008 10:56 am
Hi,
Found some php-code to use for showing the number of online users http://www.roscripts.com/How_many_visitors_online_PHP_script-108.html
From what I read, it's free to use:
Create a file called "visitors.txt" and upload it to the root of your site. Also upload the following php-code:
Create a UDT, in my case visitors, that has the following code:
Place the tag {vistors} somewhere in your template. I'm about to place it in the footer. To see an example www.uisge-beatha.eu At the moment it's placed on the right hand site on the home page.
Good luck,
Gregor
Found some php-code to use for showing the number of online users http://www.roscripts.com/How_many_visitors_online_PHP_script-108.html
From what I read, it's free to use:
Create a file called "visitors.txt" and upload it to the root of your site. Also upload the following php-code:
Code: Select all
<?php
$dataFile = "visitors.txt";
$sessionTime = 30; // this is the time in **minutes** to consider someone online before removing them from our file
//Please do not edit bellow this line
error_reporting(E_ERROR | E_PARSE);
if(!file_exists($dataFile)) {
$fp = fopen($dataFile, "w+");
fclose($fp);
}
$ip = $_SERVER['REMOTE_ADDR'];
$users = array();
$onusers = array();
//getting
$fp = fopen($dataFile, "r");
flock($fp, LOCK_SH);
while(!feof($fp)) {
$users[] = rtrim(fgets($fp, 32));
}
flock($fp, LOCK_UN);
fclose($fp);
//cleaning
$x = 0;
$alreadyIn = FALSE;
foreach($users as $key => $data) {
list( , $lastvisit) = explode("|", $data);
if(time() - $lastvisit >= $sessionTime * 60) {
$users[$x] = "";
} else {
if(strpos($data, $ip) !== FALSE) {
$alreadyIn = TRUE;
$users[$x] = "$ip|" . time(); //updating
}
}
$x++;
}
if($alreadyIn == FALSE) {
$users[] = "$ip|" . time();
}
//writing
$fp = fopen($dataFile, "w+");
flock($fp, LOCK_EX);
$i = 0;
foreach($users as $single) {
if($single != "") {
fwrite($fp, $single . "\r\n");
$i++;
}
}
flock($fp, LOCK_UN);
fclose($fp);
//:auto; background-color:#fff
if($uo_keepquiet != TRUE) {
if($i = 1) {
echo '<div style="padding:5px; margin:auto"><b>' . $i . ' bezoeker online</b></div>';
} else {
echo '<div style="padding:5px; margin:auto"><b>' . $i . ' bezoekers online</b></div>';
}
}
?>
Code: Select all
include_once "/home/gregor/domains/uisge-beatha.eu/public_html/visitors.php";
Good luck,
Gregor