Jump to content

Download Counter


Ramamoorthy

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/282625-download-counter/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/282625-download-counter/#findComment-1452147
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.