Jump to content
Larry Ullman's Book Forums

Click Counter


Recommended Posts

Guest you_n_me_n_php

Hi,

 

I'm dong a downloads page for a band http://rolandgilmer.com/impossible_tuesday/index.php. I need to be able to count how many times each download link is clicked. The following may be helpful to know:

 

1. I would like to initialize the "count" for each link at some random, arbitrary number like "1500" (for marketing purposes). I don't want to start the thing at "0" and make the band look like a bunch of nobodies.

2. I would like to record each users IP address to make sure their click is unique

3. I would like to display the click numbers right next to each download link

4. The information needn't be output anywhere else (even though I will consider outputting it to a text file for later reporting purposes if the coding doesn't get out of hand. The thing has to be complete by Saturday 7/23)

 

I was torn regarding whether or not to start writing code, as I have been advised in other forums that "providing my own answer" or telling someone "what I think" is going on can sometimes confuse the issue. Rather, as an educated beginner, it is my understanding that I should listen very closely since I have no idea where to start with this outside of the page I have herein provided. I am, however, willing to work very hard if I can be pointed in the right direction.

 

With this in mind, I thought I should start with pseudo coding, maybe?

 

If my approach is wrong, please advise. In general, I just need to know where to start. I guess the questions and the code will start on my end once that happens. Thanks!

 

Roland

Link to comment
Share on other sites

This shouldn't be hard to do, depending upon your skill level. Here's what I would do:

1. Create a database table that records the files.

2. Create a second table that records a file ID, the user's IP address, and a timestamp.

3. For the link to download a file, use a link to a "proxy script", passing along the file ID: download_file.php?id=X

4. The download_file.php script would:

A) Add a record to the second table, indicating the file ID, the IP address, and the current time.

B ) Serve the file to the user.

5. To display the number of times a file has been downloaded, just do a count for that file ID on the second table. You can add any value you want to this actual count in order to inflate the numbers.

 

That should be enough to get you started. Let us know if you have any questions or problems.

Link to comment
Share on other sites

Guest you_n_me_n_php

This shouldn't be hard to do, depending upon your skill level. Here's what I would do:

1. Create a database table that records the files.

2. Create a second table that records a file ID, the user's IP address, and a timestamp.

3. For the link to download a file, use a link to a "proxy script", passing along the file ID: download_file.php?id=X

4. The download_file.php script would:

A) Add a record to the second table, indicating the file ID, the IP address, and the current time.

B ) Serve the file to the user.

5. To display the number of times a file has been downloaded, just do a count for that file ID on the second table. You can add any value you want to this actual count in order to inflate the numbers.

 

That should be enough to get you started. Let us know if you have any questions or problems.

 

Larry,

 

PHP 6 & MySQL 5 is my first real introduction to open source web application development (or any "source" for that matter). I understand the languages from a theoretical/schematic standpoint, but haven't had much of an opportunity to put things to work in the real world--until now, that is. So no real skill level (yet). But why couldn't my little rock and roll clients choose something that was already in your book (smile)...

 

Anyway,

 

I am going to get started right away with these steps, sequentially. Thanks so much for the learning opportunity. I will be sure to follow up, posting my work with questions for the benefit of the community. After all, I have concluded from my google searches that there are a lot of people looking to do this very thing. When I am done, I will have authored my very first working PHP web application for a "real client". Then, I can actually post this online to help someone else (my first tutorial, maybe...smile)! This is exciting.

 

Well, here we go with step 1-

 

I. "Creating The Database Table That Records the Files"

 

When you say "record the files", are we talking about the actual songs themselves (they are packaged in zip files)? So INSERT into SONGS, etc.?

 

 

Thank you....

Link to comment
Share on other sites

I wouldn't put the song files in the database, just the information about each song. And there will need to be an association made between the song's record in the database and the actual file on the server (e.g., store the file's name along with the rest of the information).

Link to comment
Share on other sites

Guest you_n_me_n_php

I wouldn't put the song files in the database, just the information about each song. And there will need to be an association made between the song's record in the database and the actual file on the server (e.g., store the file's name along with the rest of the information).

 

Okay. Thanks!

Link to comment
Share on other sites

 Share

×
×
  • Create New...