There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
showing number of downloads...?


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
starchild's Avatar
Senior Member with 1,924 posts.
 
Join Date: Sep 2002
29-Jan-2004, 09:29 PM #1
showing number of downloads...?
I've been practicing making screensavers and sometimes give the link out to a webpage that has one or two on it set up as a download. Not for any reason, (I don't charge, or they're not for advertising or anything). Just to share, and maybe possible feedback.

Is there something I can write in with the link that tells me if, and how many times, one has been downloaded?

I've seen on posts here, when someone puts on a link to a graphic, it will say "this has been downloaded 4 times" (whatever)

I can put a counter/tracker on the page, but this doesn't show if anyone is downloading one of the screensavers.

I'm assuming this would be some sort of javascript code? I occasionally attempt to learn something about JS, but mainly what I've ever used has been copy/pasted from something someone else wrote (and is giving away).

And, since it should show the downloading of the actual screensaver, it might be set up inside each link in some way?

Never passing up a chance to learn something new.

Thanks!

~ Carrie
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
29-Jan-2004, 11:13 PM #2
This is pretty simple to accomplish with a little PHP

Fisrt you create two PHP pages, one called track.php and one called index.php.

First we need to create the actual tracking page.

This is the track.php page
PHP Code:
//VARIABLEs

$CHECK_URL TRUE;
$CHECK_URL_REGEX "/^(http:|ftp:\/\/).*(\.+).*/i";

$CHECK_REFERER FALSE;
$REFERER_SUBSTRING "yoursite.com";

/*--------------
DO NOT EDIT BELOW THIS LINE!
--------------*/


$QS $_SERVER["QUERY_STRING"];

if(
$CHECK_URL && !preg_match($CHECK_URL_REGEX$QS)){
    
//this didn't match
    
echo "<p>The link does not seem to point to a valid URL.</p>";
    exit;
    }

if(
$CHECK_REFERER){
    if (!
stristr($_SERVER["HTTP_REFERER"], $REFERER_SUBSTRING)){
        echo 
"<p>The referring site does not match. Please make sure that the link you clicked came from the right site.</p>";
        exit;
        }
    }
    
$LogFilePath dirname(__FILE__) . "/" md5($QS) . ".log";

//echo "Log path: " . $LogFilePath;
/*
Log file format
The file contains individual pieces of information per line. The lines are:
0: QS, which is the URL
1: Last hit unix time stamp
2: No. of requests
3: Log creation time
*/
//If the file doesn't exist, create it and write the log.
if(!file_exists($LogFilePath)){
    
touch($LogFilePath);
    
chmod($LogFilePath0666);
    
$LogString $QS "\n" time() . "\n1\n" time();
    
$FH fopen($LogFilePath"w+");
    
fwrite($FH$LogString);
    
fclose($FH);
    }
else{
    
$FA file($LogFilePath);
    
$Hits trim($FA[2]);
    
$Hits += 1;
    
$FA[2] = $Hits "\n";
    
$FA[1] = time() . "\n";
    
$LogString implode(""$FA);
    
$FH fopen($LogFilePath"w+");
    
fwrite($FH$LogString);
    
fclose($FH);
    }

header("Location: " $QS); 
Next we create the index.php page.
This pages hould have a 1 x 4 table on it.

the table creation html is
Quote:
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td class="tblHeading">Requested URL</td>
<td class="tblHeading">Number of Requests</td>
<td class="tblHeading">Most Recent Hit</td>
<td class="tblHeading">First Recorded Hit</td>
</tr>
</table>
</body></html>
the code included in it would be:

PHP Code:

    $dir 
dirname(__FILE__);
    
// Change to directory
    
chdir($dir);

    
// Open directory;
    
$handle = @opendir($dir) or die("Directory \"$dir\"not found.");

    
// Loop through all directory entries, construct
    // two temporary arrays containing files and sub directories
    
while($entry readdir($handle))
    {
        if(
$entry != ".." && $entry != "."){
            
$PathParts pathinfo($entry);
            if(
$PathParts["extension"] == "log"){
                
$dir_files[] = $entry;
                }
        }
    }

    
// Print all files in the curent directory
    
for($i=0$i<count($dir_files); $i++){
        
$FA file($dir_files[$i]);
        echo 
"<tr><td class=\"DataTD\"><a href=\"" $FA[0] . "\">".$FA[0]."</a></td><td class=\"DataTD\">".$FA[2]."</td><td class=\"DataTD\">".date("D dMy\nh:iA"$FA[1])."</td><td class=\"DataTD\">".date("D dMy\nh:iA"$FA[3])."</td></tr>";
    }

    
// Close directory
    
closedir($handle); 
Next we track the links.
Any link you want tracked (say www.yoursite.com/file1.zip) then your link would need to be:
/trak.php?http://www.yoursite.com/file1.zip

note!!
the /track.php assumes you created this in the same directory as the rest of your links files.


Good luck with it.
__________________
Good Luck on your fix

My real hobby..JoyCo
My real Job..(Second Hobby) IAFF Local 1865
Like the sites? My hobby is the one that created them!
starchild's Avatar
Senior Member with 1,924 posts.
 
Join Date: Sep 2002
30-Jan-2004, 12:14 AM #3
Thanks!

It'll be a project for tomorrow.

~ Carrie
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:21 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.