---
title: "Sätt ip på räknare så den inte räknar sig själv"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/85931-sätt-ip-på-räknare-så-den-inte-räknar-sig-själv"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "silfver"
published: "2003-09-13T13:21:56.000Z"
updated: "2003-09-13T13:29:14.000Z"
replies: 1
views: 457
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/85931-sätt-ip-på-räknare-så-den-inte-räknar-sig-själv"
---

# Sätt ip på räknare så den inte räknar sig själv

## #1 — silfver, 2003-09-13T13:21Z

Hur ska jag göra för att göra så att mitt egna ip inte räknas?
Går det med den koden jag har? Om man lägger till någon extra sträng.

```php
<?php 

$cfile = "count.txt"; // The filename of the counter, has to be chmod 777. 

function counter($filename) { 
    $fd = fopen($filename, "r+"); 
    $contents = fread($fd, filesize ($filename)); 
    $contents = $contents +1; 
    fclose($fd); 
    $fd = fopen($filename, "w+"); 
    $write = fputs($fd, $contents, strlen($contents)); 
    fclose($fd); 
} 

function showcounter($filename) { 
    $fd = fopen($filename, "r+"); 
    $contents = fread($fd, filesize ($filename)); 
    fclose($fd);     
    return $contents; 
} 

counter($cfile); // Adds/counts a visitor. 

echo showcounter($cfile); // Prints the number of visitors. 
?>
```

 

Mvh silfver

Permalänk: https://www.webforum.nu/p/85931

## #2 — Gein, 2003-09-13T13:29Z

Kolla bara om besökaren är från ditt egna ip. Om inte, så gör du funktionen counter

```php
<?php 

$cfile = "count.txt"; // The filename of the counter, has to be chmod 777. 

function counter($filename) { 
    $fd = fopen($filename, "r+"); 
    $contents = fread($fd, filesize ($filename)); 
    $contents = $contents +1; 
    fclose($fd); 
    $fd = fopen($filename, "w+"); 
    $write = fputs($fd, $contents, strlen($contents)); 
    fclose($fd); 
} 

function showcounter($filename) { 
    $fd = fopen($filename, "r+"); 
    $contents = fread($fd, filesize ($filename)); 
    fclose($fd);     
    return $contents; 
} 

if($_SERVER['REMOTE_ADDR'] != "192.168.0.1"){
    counter($cfile); // Adds/counts a visitor. 
}

echo showcounter($cfile); // Prints the number of visitors. 

?>
```

 

Byt ut 192.168.0.1 till ditt lokala IP.

Permalänk: https://www.webforum.nu/p/1155984

---

Tråden på webben: https://www.webforum.nu/amne/php/85931-sätt-ip-på-räknare-så-den-inte-räknar-sig-själv
