Reputation: 105
I have the following simple count, system and I have 2 things, that I can't do. Here is my count.php file:
<?php
if (file_exists('admin/all_count.txt')){
$fil = fopen('admin/all_count.txt', r);
$dat = fread($fil, filesize('admin/all_count.txt'));
echo $dat+1;
fclose($fil);
$fil = fopen('admin/all_count.txt', w);
fwrite($fil, $dat+1);
}
else
{
$fil = fopen('admin/all_count.txt', w);
fwrite($fil, 1);
echo '1';
fclose($fil);
}
?>
Here is the content of the all_count.txt file (but I don't think you need it, anyway):
81
Questions:-
<?php include("count.php");
?>
inside the page which counts I would like to count, BUT where I
put this include, it is showing the actual content of all_count.txt
file in the webpage, which I would like to be hidden. I tried this for making it zero a week ago, but didn't work: I tried this for make it zero, and didn't work: zero.php:
<?php
if (file_exists('admin/all_count.txt')){
$fil = fopen('admin/all_count.txt', r);
$dat = fread($fil, filesize('admin/all_count.txt'));
$dat-$dat;
fclose($fil);
$fil = fopen('admin/all_count.txt', w);
fwrite($fil, $dat-$dat);
}
else
{
$fil = fopen('admin/all_count.txt', w);
fwrite($fil, 0);
echo '0';
fclose($fil);
}
?>
Upvotes: 1
Views: 306
Reputation: 3484
in order to zero the content of the file oyu can just do
file_put_contents('admin/all_count.txt','0');
You can just use file_get_contents/file_put_contents - I think it will be easier for you.
Upvotes: 3
Reputation: 2579
Don't use echo
if you don't want stuff to show up on your page.
you already have a way to write the count to your txt file, why wouldn't you be able to just write 0 to it?
Upvotes: 1