Код за онлайн потребители

  • Автор Автор CeVo
  • Начална дата Начална дата
Заповядай
Код:
<? 
$ip = $_SERVER['REMOTE_ADDR']; 
$time = time(); 
$cutoff = 15; //online cut of time 
$exists = 0; 
$users = 0; 
$user = ""; 

$fp = fopen ("online.txt","r+"); //if the file exists open it 

while (!feof($fp)) 
{ 
$user[] = chop(fgets($fp,65536)); 
} 
fseek($fp,0,SEEK_SET); 


foreach ($user as $line) 
{ 
list($oldip,$oldtime) = explode('|',$line); 
if ($oldip == $ip) {$oldtime = $time;$exists = 1;} //check to see if the user is already in the text file 
if ($time < $oldtime + ($cutoff * 60)) //see if the last time the user visited is past the cut off time 
{ 
fputs($fp,"$oldip|$oldtime\n"); //write the old data to the text file 
$users = $users + 1; // add one to the user count 
} 
} 


if ($exists == 0) //if the user isn't in the text file already: 
{ 
fputs($fp,"$ip|$time\n"); //write the new data to the text file 
$users = $users + 1; //add one to the user count 
} 


fclose ($fp); //close the text file 
print "Гости Онлайн: $users"; //display the number of users online 

?>
 
CeVo каза:
не ми върши работата други кодове

Е кво значи не ми върхи работа..
Обесни какво точно искаш и кое точно не ти харесва на тоя код..
 
ExpressYourself каза:
CeVo каза:
не ми върши работата други кодове

Е кво значи не ми върхи работа..
Обесни какво точно искаш и кое точно не ти харесва на тоя код..

Да напиши във файл ли да се записват IP тата или в ДБ :?
 

Back
Горе