mi viene più semplice riscriverlo

codice:
<?
$countertype = "image"; // put "text" or "image", choose which counter style you want
$imagetype = ".gif"; // if using "image" above, put in the extension with the '.' of the img files. ie: ".gif",".jpg",".png"
$numofdigits = 4; // number of digits to show, if number of digits in hits is less than this, tack as many '0's on the front as needed
$percorso = "images/counter/"; // percorso per trovare le immagini cart/cart/
// configuration STOPS here

$file_counter = '../counter/main.txt';
session_start();

if(!file_exists($file_counter)) {
    // crea il file contatore se non esiste
    touch($file_counter);
}

if(!isset($_SESSION['counter']) || (isset($_SESSION['counter']) && $_SESSION['counter'] != 'isset')) { // se la sessione non esiste
     $_SESSION['counter'] = 'isset'; // crea la sessione
     $visits = intval(trim(file_get_contents($file_counter))); // legge il contatore
     ++$visits; // aggiorna il contatore
     $fp = fopen($file_counter, 'w'); // aggiorna il file contatore
     fputs($fp, $visits);
     fclose($fp);
} else { // se esiste la sessione
     $visits = intval(trim(file_get_contents($file_counter))); // legge il contatore
}

$visits = sprintf("%0{$numofdigits}d", $visits); // formatta il contatore con gli zero

if($countertype == 'image') { // se il formato è immagine
   $img_output = '';
   $len = strlen($visits);
   for($x = 0; $x < $len; ++$x) {
       $img_output .= "<img src=\"{$percorso}{$visits[$x]}{$imagetype}\">"; // crea i tag immagine
   }
   $visits = $img_output;
}

echo $visits; // stampa il contatore
?>