I have a simple hit counter where I save the IP and country of visitors, but after some hits the file where I write the visits fills with empty lines
This is the result:
<myip>|GR
<myip>|GR
<myip>|GR
<myip>|GR
<myip>|GR
This is the code:
<?php
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
$location = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
$entries = file("hitcounter.txt");
array_push($entries,$ip."|".$location->country);
$newEntries=implode($entries,"\n");
$fp = fopen("hitcounter.txt" ,"w");
fputs($fp , $newEntries);
fclose($fp);
function echoVisits(){
$entries = file("hitcounter.txt");
echo count($entries);
}
?>
So why do I end up with a file with empty lines?