Code: Select all
<?php
$not_open = 0;
if(($counter = fopen("counter.txt", "r")) == NULL)
$not_open = 1;
if($not_open == 0)
{
fscanf($counter, "%d", $number);
fclose($counter);
$number++;
$not_open = 0;
if(($counter = fopen("counter.txt", "w")) == NULL)
$not_open = 1;
if($not_open == 0)
{
fprintf($counter, "%d", $number);
fclose($counter);
}
}
?>Why doesn't this piece of code work? Problem is with fprintf in the end... Second fopen opens the file for writing and deletes it's content, but fprintf doesn't write anything to it... As a result, i get a blank file counter.txt and HTML page, of which this code is part, doesn't show... I only get blank file...
Thanks for any help!