Txt dosyası kullanarak online ziyaretçi sayısını gösteren fonksiyon.
(fonksiyonu çağırdığınız dosyanın bulunduğu dizinde ip.txt olmalıdır) function onlinesay($zamanasimi = '300'){
$rip = $_SERVER['REMOTE_ADDR'];
$sd = time();
$rand = rand(3,5);
$onlineUsers = $rand;
$file1 = "ip.txt";
$lines = file($file1);
$line2 = "";
foreach ($lines as $line_num => $line)
{
$fp = strpos($line,'****');
$nam = substr($line,0,$fp);
$sp = strpos($line,'++++');
$val = substr($line,$fp+4,$sp-($fp+4));
$diff = $sd-$val;
if($diff < $zamanasimi && $nam != $rip)
{
$onlineUsers = $onlineUsers+1;
$line2 = $line2.$line;
}
}
$my = $rip."****".$sd."++++\n";
$open1 = fopen($file1, "w");
fwrite($open1,"$line2");
fwrite($open1,"$my");
fclose($open1);
echo "$onlineUsers";
}time() fonksiyonunu kullanarak geçen zamanı hesaplayan basit bir fonksiyon. Mesaj sistemlerinde yada son login zamanı gibi şeyler yapmak istediğinizde kullanabilirsiniz.
function once($time)
{
$time_difference = time() - $time;
$seconds = $time_difference ;
$minutes = round($time_difference / 60 );
$hours = round($time_difference / 3600 );
$days = round($time_difference / 86400 );
$weeks = round($time_difference / 604800 );
$months = round($time_difference / 2419200 );
$years = round($time_difference / 29030400 );
// Seconds
if($seconds <= 60){
echo "$seconds saniye önce";
}elseif($minutes <=60){
echo "$minutes dakika önce";
}elseif($hours <=24){
echo "$hours saat önce";
}elseif($days <= 7){
echo "$days gün önce";
}elseif($weeks <= 4){
echo "$weeks hafta önce";
}elseif($months <=12){
echo "$months ay önce";
}else{
echo "$years yıl önce";
}
}