24, July 2008

count downloads script - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ 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

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



« on: Sep 01, 2005, 12:08:19 PM »

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: 7975
40807 credits
Members referred : 3



« Reply #1 on: Sep 01, 2005, 12:22:06 PM »

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 Visit through proxy

Last blog : MIA - Where Nick and Tim
I wish I was an Oscar winner
**
Posts: 86
247 credits
Members referred : 0



« Reply #2 on: Sep 01, 2005, 12:34:15 PM »

Thanks Nikolas. I really apreciate this

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



« Reply #3 on: Sep 01, 2005, 12:40:43 PM »

Welcome my friend Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Novice Spammer
***
Posts: 100
103 credits
Members referred : 0



« Reply #4 on: Sep 08, 2005, 07: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....

Topic sponsors:
Get a permanent link here for $1.99!


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?
Jul 24, 2008, 10:15:09 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!


Forum Statistics
Total Posts: 35.717
Total Topics: 7.379
Total Members: 3.710
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: prolist

42 Guests, 3 Users online :

10 users online today:



Readers

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