Jump to content

Download Counter


Ramamoorthy
Go to solution Solved by requinix,

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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.