This is counter.txt:
And this is the program I wrote that I access with somthing like:
<IMG SRC="fileincrement.php3?nome=main" height="0" width="0">
<?
// - chmod this document to 755! -
$fpt = "counter.txt"; // path to log file - chmod it to 666
echo $nome;
if (!file_exists($fpt)) {
$count_dat = fopen($fpt,'w+');//aprerto in scrittura e se non esiste lo crea
$count = 1;
fwrite($count_dat,$count);
fclose($count_dat);
}
//take $nome from the page that called the *.php3 and decide which counter to incrememnt
else {
switch ($nome) {
case main:
$position=0;
break;
case msc:
$position=1;
break;
case kd:
$position=2;
break;
case american:
$position=3;
break;
case cruisewest:
$position=4;
break;
case norwegian:
$position=5;
break;
case delimann:
$position=6;
break;
case riverbarge:
$position=7;
break;
case royal:
$position=8;
break;
case star:
$position=9;
break;
case temptress:
$position=10;
break;
case windjammer:
$position=11;
break;
case world:
$position=12;
break;
}
$line = file($fpt); //Reads entire file into an array
echo "prima incremento";
echo $line[$position];
$line[$position]=$line[$position]+1;; //incrementa il contatore della pagina vista
echo "dopo incremento";
echo $line[$position];
$tempfile = fopen("tempfile.txt",'w+'); //nuovo file
fwrite($tempfile, $line); //write the array in tempfile
fclose($tempfile); //chiude il tempfile
copy("tempfile.txt","counter.txt"); //sovrascrive il counter con il tempfile
//delate tempfile
$EraseAll = fopen("tempfile.txt",'w');
fwrite($EraseAll,"");
fclose($EraseAll);
}
?>
Could you be so kind to tell me why "fwrite($tempfile, $line); " this is not working and my counter.txt becomes like this: Array?
Thank you
Maria Elena