Webmaster общности: Predpriemach.com | SearchEngines.bg

    PHP – Колко човека са онлайн

    Здравеите,
    Това е скрипт които показва калка човека разглеждат сайта ви

    <?
    
    $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
    
    ?>