Ramamoorthy Posted October 2, 2013 Share Posted October 2, 2013 I am creating a download counter for my website , where the counts will be saved in a text file. and then it will be incremented everytime the page gets the visit . It contains 3 files; counter.php - increments the count everytime the page gets hits log.txt - numerical value will be stored here display.php - gets the content from log.txt and prints it . Codes Counter.php <html><head> <meta http-equiv="refresh" content="0; url=http://localhost:1000/hits/test.zip"> </head> <?php $fp = fopen("log.txt", "r"); $count = fread($fp, 1024); fclose($fp); $count = $count + 1; $fp = fopen("counterlog.txt", "w"); fwrite($fp, $count); fclose($fp); ?> display.php <?php$fp = fopen("log.txt", "r"); $count = fread($fp, 1024); fclose($fp); echo "<span class='span-counter'>" . $count . "</span>"; ?> log.txt 1 The above codes works fine . It increments the count and writes to text file . and I can display the Number of Downloads wherever I want . Now I want to make it for more than 100 downloads(100 types) .. that uses same log.txt file for writing . How it is possible ..? can I write in specific line number in php using fwrite or someother function .? or I have to use database for this ? -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/282625-download-counter/ Share on other sites More sharing options...
requinix Posted October 2, 2013 Share Posted October 2, 2013 I am creating a download counter for my website , where the counts will be saved in a text file.Don't use a file. Use a database for it. Then you can keep counters for as many things as you want. Quote Link to comment https://forums.phpfreaks.com/topic/282625-download-counter/#findComment-1452144 Share on other sites More sharing options...
Ramamoorthy Posted October 2, 2013 Author Share Posted October 2, 2013 Don't use a file. Use a database for it. Then you can keep counters for as many things as you want. anyway to create without database .? I dont know mysql ! Quote Link to comment https://forums.phpfreaks.com/topic/282625-download-counter/#findComment-1452145 Share on other sites More sharing options...
Solution requinix Posted October 2, 2013 Solution Share Posted October 2, 2013 Start learning. Are you familiar with the phrase "when all you have is a hammer, everything looks like a nail"? Wanting to make a counter and applying your knowledge of files to it is not the answer. Instead you should be wondering what the best method for the counters is, and that would be a database. Quote Link to comment https://forums.phpfreaks.com/topic/282625-download-counter/#findComment-1452147 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.