webForumDet fria alternativet

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

PHP

1 svar · 453 visningar · startad av silfver

Medlem sedan apr. 200312 679 inlägg
Frågan#1

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 

$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

Medlem sedan sep. 20005 700 inlägg
#2

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

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

262 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
122 ms — deklarationer (db)
0 ms — hämta statistik (cache)
135 ms — hämta tråd, inlägg och bilagor (db)
124 ms — ändringar (db)