Hi, people! I started reading Php about half a year ago. Itīs going
slooow...Well, now I want to add the first php magic to my site, which is
100% made in Flash. I loaded my Php script into Flash, and made sure I had
named my Flash variables similar to the ones in the Php script. I had one
for visitors, one for last access time. I get the visitor numbers all
right, but every time I refresh the Flash movie, the counter adds
2,3,5,7,10 etc!!Itīs like a random chaos in there!I cannot trust it! Oh,
hereīs the script:
<?php
//last_counter_access.php
$counter_file = "./counter.dat";
if (file_exists($counter_file)) {
$date_str= getdate (fileatime($counter_file));
$year = $date_str["year"];
$mon = $date_str["mon"];
$mday = $date_str["mday"];
$hours = $date_str["hours"];
$minutes = $date_str["minutes"];
$seconds = $date_str["seconds"];
$date_str = "$hours:$minutes:$seconds: $mday/$mon/$year";
if (! ($fp = fopen ($counter_file, "r+")))
die ("Cannot open $counter_file");
$counter = (int) fread ($fp, filesize($counter_file));
$counter++;
echo "Visitors: $counter. ";
// Here I would say print "&counter=".$counter;
But this generates errors, why? (And yes, my variable in Flash is called
counter...)
echo "<BR>Last access: $date_str";
//And here I would say print "&date_str=".$date_str;
and have a variable in Flash called...date_str!
rewind($fp);
}
else {
if (! ($fp = fopen($counter_file, "w")));
die ("Cannot open $counter_file");
$counter = 1;
echo "Visitors: $counter.";
}
fwrite($fp, $counter);
fclose($fp);
?>
Note that I donīt use any db, only this "counter.dat"-file...Would be glad
for any help!