Sinisterly
Simple views counter (No DB used) - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: PHP (https://sinister.ly/Forum-PHP)
+--- Thread: Simple views counter (No DB used) (/Thread-Simple-views-counter-No-DB-used)



Simple views counter (No DB used) - Coder-san - 06-27-2011

I needed this for a test, but I'm too lazy to use MySql, so I made this.

First create a "testFile.txt", and enter "0" (without quotes) in it. Then add this in a php file.

PHP Code:
<?php $myFile = "testFile.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); intval($theData); $theData = $theData + 1; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $theData); fclose($fh); echo $theData; ?>