<?phpclass kimlerCevrimici{public $yol;var $dakika = 5;var $dosya = 'gecmis.txt';var $gecmis = array();var $sayac = 0;function __construct(){if(!file_exists($this->dosya)){file_put_contents($this->dosya,"");}}function kullaniciAl($ip){$dosya = fopen($this->yol . $this->dosya, 'r');$gecmis = '';while (!feof($dosya)) {$gecmis .= fread($dosya, 8192);}fclose($dosya);$this->gecmis = explode('|', $gecmis);$p = strpos($gecmis, $ip);if ($p === false){$this->gecmis[sizeof($this->gecmis)] = $ip.','.time();}}function guncelle(){if ($dosya = fopen($this->yol . $this->dosya, 'w+')){$gecmisMetin = '';foreach($this->gecmis as $i => $v){if (strlen(trim($v)) > 0){$kullanici = explode(',', $v);$gecmisMetin .= $kullanici[0].','.$kullanici[1].'|';}}$gecmisMetin = substr($gecmisMetin, 0, strlen($gecmisMetin) - 1);if (fwrite($dosya, $gecmisMetin)){return true;}else{return false;}}else{return false;}}function kac($ip){$this->kullaniciAl($ip);$this->sayac = 0;foreach($this->gecmis as $i => $v){$kullanici = explode(',', $v);if ($kullanici[1] > (time() - $this->dakika * 60) || $kullanici[0] == $ip){$this->sayac++;}else{$gecmis[$i] = '';}}$this->guncelle();return $this->sayac;}}$u = new kimlerCevrimici;echo $u->kac($_SERVER['REMOTE_ADDR']);?>
Çıktısı
2
gecmis.txt
212.74.253.133,1527946050|173.247.117.141,1527946093