Is This Code OK?
| From: | iGuru | Date: | Sat, 21 Oct 2000 07:55:03 +0000 |
| Subject: | Is This Code OK? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-21536@lists.php.net to get a copy of this message | ||
Can anyone please check if the below mentioned code is correct or can be
reduced further. I am trying to make a simple page counter with this code.
Note that the data.txt file only contains the number '1' at startup.
Can you please check if the below mentioned code is correct or can be
reduced further. I am trying to make a simple page counter with this code.
Note that the data.txt file only contains the number '1' at startup.
<?php
$file_loc = "data.txt";
$oldfile = fopen($file_loc,"r");
$file_contents = fread($oldfile,filesize($file_loc));
$oldval = $file_contents;
fclose($oldfile);
$newfile = fopen($file_loc, "w+");
echo $old;
$old = fread($newfile, $newfile);
$newval=$oldval+1;
fwrite($newfile, "$newval");
fclose($newfile);
echo $newval;
?>