Is there a way to avoid opening and closing the file "viscount" twice in this
code:
<?php
$file = 'viscount.txt';
if ($counter = @file ($file)) {
$line = each($counter);
if (!$counter) {
$counter = 1;
} else {
$counter = $line[value]+1;
}
}
$fp = fopen ($file, "w");
fwrite ($fp, "$counter") ;
fclose($fp);
$fp = fopen ($file, "r");
$count = fgets($fp);
echo $count;
?>
I tried this:
$fp = fopen ($file, "r+");
fwrite ($fp, "$counter") ;
$count = fgets($fp);
echo $count;
But $count returned an empty string (or would not echo).
code:
<?php
$file = 'viscount.txt';
if ($counter = @file ($file)) {
$line = each($counter);
if (!$counter) {
$counter = 1;
} else {
$counter = $line[value]+1;
}
}
$fp = fopen ($file, "w");
fwrite ($fp, "$counter") ;
fclose($fp);
$fp = fopen ($file, "r");
$count = fgets($fp);
echo $count;
?>
I tried this:
$fp = fopen ($file, "r+");
fwrite ($fp, "$counter") ;
$count = fgets($fp);
echo $count;
But $count returned an empty string (or would not echo).
Comment