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

<?php
$filename = "uniqueLogs.txt";

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

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

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

n203.87.184.2n203.87.184.2n222.127.223.71n203.87.184.2n203.87.184.2n203.87.184.2n203.87.184.2
.....

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

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

$ip_array=file($filename);
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.