beh, l'avete trovata
questo script usa i file.
online.class.php
codice:
<?php
class usersOnline {
var $users_file;
var $timeout;
var $timestamp;
var $ip;
function usersOnline($file_, $timeout_) {
global $_SERVER;
$this->timestamp = time();
$ip_ = ($_SERVER['REMOTE_ADDR'] != "" && preg_match("/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/", $_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : "non rilevato";
$this->ip = $ip_;
$this->users_file = $file_;
$this->timeout = $timeout_;
$this->newUser();
$this->deleteUser();
}
function newUser() {
$content = file_get_contents($this->users_file);
$lines = file($this->users_file);
foreach($lines as $line) {
$linea = explode("|", $line);
if($linea[0] == $this->ip) {
return;
}
}
$ip = $this->ip;
$timestamp = $this->timestamp;
$content .= "\n$ip|$timestamp";
writeFile($this->users_file, trim($content));
}
function deleteUser() {
$file = file($this->users_file);
foreach($file as $key => $line) {
$linea = explode("|", $line);
$aa = $this->timestamp - $this->timeout;
if($linea[1] < $aa && $linea[0] != $this->ip) {
unset($file[$key]);
}
}
writeFile($this->users_file, trim(str_replace("\n\n", "\n", implode("\n", $file))));
}
function countVisits() {
return count(file($this->users_file));
}
}
?>
per applicare basta fare:
codice:
<?php
require("online.class.php");
$online = new usersonline("online.txt", 3*60);
echo "Utenti online: ".$online->countVisits();
?>
Cià