Ceci te sert à rien :
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
$link = "https";
} else {
$link = "http";
// Here append the common URL characters.
$link .= "://";
// Append the host(domain name, ip) to the URL.
$link .= $_SERVER['HTTP_HOST'];
Mets directement l'URL de ton site dans $link, au départ, puis ajoute REQUEST_URI.
Aussi, ceci est inutile, il sera toujours "writable" ton compteur.txt :
if (is_writable($filename)) {
La concaténation PHP est incorrecte ici :
if (fwrite($handle,strftime("%A %d %B %G %H:%M:%S", strtotime($date1))."\t $somecontent.$link.\r\n") === FALSE) {
Correction :
if (fwrite($handle,strftime("%A %d %B %G %H:%M:%S", strtotime($date1))."\t" . $somecontent . $link . "\r\n") === FALSE) {
ATTENTION : $date1 ne sera jamais définit si $_SERVER['HTTP_X_FORWARDED_FOR'] existe, la condition PHP est biscornue.