Loading:


Licznik odwiedzin strony z filtrem adresów IP

Skrypt wyświetla ilość odwiedzin witryny z filtrem adresów IP

Potrzeba:

- visited_ip.txt

- counter.txt



Napisz Artyku³

Listing


<?PHP

function alreadyVisited($ip)
{
  if(($fd = @fopen("visited_ip.txt", "r+")) === false)
    return false;

  while(!feof ($fd)){
    $line = trim(fgets($fd));
    if($line == $ip){
      fclose($fd);
      return true;
    }
  }
  fputs($fd, $ip."\r\n");
  fclose($fd);
  return false;
}

function getCounter()
{
  if(($fp = @fopen("counter.txt", "r+")) === false)
    return "0";
  $count = fgets($fp);

  if(!alreadyVisited($_SERVER['REMOTE_ADDR'])){
    $count = $count + 1;
    fseek($fp, 0);
    fputs($fp, $count);
  }
  fclose($fp);

  $count = strval($count);
  $strLength = strlen($count);
  $imgStr = "";

  for($i = 0; $i < $strLength; $i++){
    $temp = $count[$i]. '.gif';
    $imgStr .= "<IMG SRC='$temp'>";
  }
  return $imgStr;
}

echo(getCounter());
?>
 




Dodano przez: igor
Ranga: Administrator serwisu Punktów: 28716
Komentarze użytkowników
    • Tre¶æ komentarza
      Kod do komentarza (opcjonalnie)
      PHP JavaScript MySQL Smarty SQL HTML CSS ActionScript
      Autor
      Token
      token

       

       








funkcje.net
Wszelkie prawa zastrzeżone©. | Funkcje.net 2008-2024 v.1.5 | design: diviXdesign & rainbowcolors