I've Install this script to my site but It won't function that well

Here's the code, which logs client side IP in a flat file or *.txt

$filename = "uniqueLogs.txt";

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename));
$fd = fopen ($filename , "w");
$fcounted = $fstring."\n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );

but if you will look to that file/ *.txt it logs the IP horizontally


What I notice is the script is unreliable because it won't show the right numeral's for its the number of user visited the site and the file continues to write on the flat file w/c was been already log.

My question was their a function that logs and write without replicates..

10 Years
Discussion Span
Last Post by nav33n

Do you want unique ips to be put in that text file ? If thats the case, then you fetch the contents of the file uniqueLogs.txt as an array. Then, check if the ip address of the visitor is in that array. If it exists, then don't write the ip to the file, else, write the ip.

if(! in_array($visitor_ip, $ip_array)){
 //write $visitor_ip to $filename
} else {
// $visitor_ip is already in the file.. do nothing 

Basically, it all depends on how you save the ip in the text file. Make sure you write it in such a way that its easier to access and use.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.