Hello friends, I am having an app for downloading. But i want to know how many of them are downloading. How to create a download counter in PHP or any other script.
Create a table or just a file on your server which has write permissions. On the link where user downloads the file. Just read the counter from file or table and update counter with counter = counter + 1. Use some meta refresh tag after that update line to redirect user for downloading the app. Thanks.
Sorry Nick_Mayhem, i am not an expert in PHP. Please give a tutorial on your above post, if you have time. Thanks for your patience.
if you have a MySQL DB with name BASE1, table TABLE1 and with 2 fields DOWNLOADS and APP_ID then $db = mysql_connect("MySQL SERVER HERE or localhost as default", "MySQL LOGIN HERE", "MySQL PASSWORD HERE"); $APP_ID = $_GET['id']; mysql_select_db("BASE1",$db); $result = mysql_query("SELECT * FROM TABLE1 WHERE APP_ID='$APP_ID'",$db); $result = mysql_fetch_array($result); { $downloads = $result["DOWNLOADS"]; $downloads++; mysql_query("UPDATE TABLE1 SET DOWNLOADS='$downloads' WHERE APP_ID=$APP_ID"); } mysql_close($db); PHP: try to do it this way =) if you are totally newb in PHP, then try to read some PHP tutorials... cheers
Or you could use a pre-made script which does it all for you. I use ccount, just google it, works great for me.
Here's a simple download counts without DB. Save the following as anyfilename.php <?php $fp = fopen("dlcounts.txt", "r"); if (!$fp) die("Cannot open file(r)"); $number = fread($fp, filesize("dlcounts.txt")); $number++; fclose($fp); $fp = fopen("dlcounts.txt", "w"); if (!$fp) die("Cannot open file(w)"); fwrite($fp, $number); fclose($fp); //Place you file here $cm = "Location:yourfilename.zip $file"; header ($cm); ?> PHP: Create a text file named dlcounts.txt and chmod permission to 777. Place them in the same directory. Access the download at anyfilename.php Get the download counts by echo the following code: <?php $fp = fopen("dlcounts.txt", "r"); echo fread($fp, filesize("dlcounts.txt")); fclose($fp); ?> PHP: