28, May 2012

count downloads script - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: count downloads script
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: count downloads script  (Read 1179 times)
I wish I was an Oscar winner
**
Posts: 86
247 credits
Members referred : 0



« on: Sep 01, 2005, 11:08:19 am »

I would like to create a script that will be able to track downloads from my page. eg. the user clicks to a link to download.php?id=1 and the script gives the file that haves id 1 in a mysql database, and counts the hit.

Is there any script capable to do this?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Sep 01, 2005, 11:22:06 am »

Well here is your script :

Code:
<?php

//Avoid fake hits

if ( ! isset($id) )
{
    exit;
}

//This $db stuff can be changed to whatever you use for integration with mySql

/*
Table structure :

id -> id of download
file -> filename with path
hits -> how many times downloaded

*/

$db = new DB_Class();
$db->query("SELECT file FROM downloads WHERE id = '$id' LIMIT 1");
$db->next();
$URL $db->Record[0];

$db->query("UPDATE LOW_PRIORITY downloads SET hits = hits + 1 WHERE id = '$id' LIMIT 1");

$f fopen($URL"rb"); 
$content_len filesize($URL); 
$content_file fread($f$content_len); 
fclose($f); 

@
ob_end_clean(); 
@
ini_set('zlib.output_compression''Off'); 

//Some error reporting:
if ( ! file_exists $URL ) )
{
     die ( 
"The file you asked does not exists" );
}

header("Cache-Control: no-store, no-cache, must-revalidate");                  
header("Cache-Control: post-check=0, pre-check=0"true);                      
header("Pragma: no-cache");                                                    
header("Expires: 0");
header("Content-disposition: attachment; filename=" basename$URL ));  
header("Content-type: application/force-download");

echo 
$content_file
?>


Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
I wish I was an Oscar winner
**
Posts: 86
247 credits
Members referred : 0



« Reply #2 on: Sep 01, 2005, 11:34:15 am »

Thanks Nikolas. I really apreciate this

Smiley
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #3 on: Sep 01, 2005, 11:40:43 am »

Welcome my friend Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Novice Spammer
***
Posts: 100
103 credits
Members referred : 0



« Reply #4 on: Sep 08, 2005, 06:36:38 am »

What that script does is store the count in a database. It takes the count amount from database, adds 1 to the number of hits, and then stores it back into the database. (Just explaining to people who dont understand how it works)
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=76
Tags : mysql databases Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: count downloads script
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 09:52:24 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.