Çarşamba, Temmuz 10, 2013

php online kullanıcı sayısı


$folder = dirname(__FILE__)."/activeusers/";
$timeold=30;   // seconds
$actualtime=date("U");   // seconds since January 1st, 1970.

$ip = "0.0.0.0";
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
if(isset($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];
file_put_contents ($folder."$ip.$actualtime.txt", "0");

$counter=0;
$ipCounter = array();

$dir = dir($folder);
while($temp = $dir->read()){
if ($temp=="." or $temp==".."){continue;}
$filecreatedtime=date("U", filemtime($folder.$temp));
if ($actualtime>($filecreatedtime+$timeold)){
unlink ($folder.$temp);                                                                   //
}else{
$dataArr = explode('.',$temp);
$dataIp = sprintf('%s', $dataArr[0], $dataArr[0], $dataArr[0], $dataArr[0]);
$ipCounter[$dataIp] += 1;
$counter++;

if($ipCounter[$dataIp]>15) {
echo ":)";
exit(0);
}
}
}

Hiç yorum yok: