How to detect downloading from my website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
julianbury
Forum Newbie
Posts: 3
Joined: Thu Oct 29, 2009 3:25 pm

How to detect downloading from my website

Post by julianbury »

Dear Coders,

There are six games on my website which can be downloaded for free.
There is a separate download page for each game.
I have a counter for visits to each download page.
There is a picture of the game on its page, for example: Greed.jpg

But, visits to the page may not result in downloads.
How can I detect actual downloads?
Here is the current code for the "Greed" download page ...

The visits counter ...
<?php $hits=file("../Greed.x"); $hits[0]++; $fp=fopen("../Greed.x","w"); fputs($fp,$hits[0]); fclose($fp); ?>

The picture ...
<p style="text-align:center;"><img src="Greed.jpg"/></p>

The download link ...
<a href="Install_Greed.exe"><br/>Download Greed</a>

That's it.
Now, how do I confirm that a download occurred?

Thank you for your kind attention :D

(-_-)
rnoack
Forum Commoner
Posts: 34
Joined: Mon May 03, 2010 12:38 am

Re: How to detect downloading from my website

Post by rnoack »

make a file called download.php

Code: Select all

<?php 
if (!isset($_GET['path']) { echo "no file specified }
else
{    
   // insert your php code similar to the other page here to increment your counter file
   header("Location: $_GET['path']");
} 
?>
and make the link on the other page to:
<a href= "download.php?path=Install_Greed.exe"><br/>Download Greed</a>


something like that... adjust as you like... you could make it nice and generic to use on every release.
alternatively you could make a seperate download.php file for every game and hard-code the path
julianbury
Forum Newbie
Posts: 3
Joined: Thu Oct 29, 2009 3:25 pm

Re: How to detect downloading from my website

Post by julianbury »

I have not been able to make it work.
I do not understand the mechanism (obviously).
What I am getting is the counter advancing, no download and a blank page.
see for yourself at http://julianbury.com/games/

Here are the two files are here in their entirety:

Greed.php ...
==================================================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="../index.css" />
<title>julianbury.com</title>
</head><body><center>
<div style="width:1000px;">
<?php $data=file('../links.txt'); $n=count($data); for( $i=0; $i < $n; $i++){ print $data[$i]; } ?>

<p style="text-align:center;"><img src="Greed.jpg"/></p>
<a href= "Greed_download.php?path=Install_Greed.exe"><h1>Download Greed</h1></a>

</div></center></body></html>
==================================================================================

Greed_download.php ...
==================================================================================
<?php
if (isset($_GET['path']){
$hits=file("../Greed.x");$hits[0]++;$fp=fopen("../Greed.x","w");fputs($fp,$hits[0]);fclose($fp);
header("Location:$_GET['path']");
}
header("Location:"index.php");
?>
==================================================================================

What am I doing wrong?

I am sorry to be such an ignorant pain in the arse.

(-_-)
rnoack
Forum Commoner
Posts: 34
Joined: Mon May 03, 2010 12:38 am

Re: How to detect downloading from my website

Post by rnoack »

ok, just to make it more simple, try it like this and see if you can get it:

Greed_download.php

Code: Select all

<?php 
$hits=file("../Greed.x");$hits[0]++;$fp=fopen("../Greed.x","w");fputs($fp,$hits[0]);fclose($fp);
header("Location: Install_Greed.exe");
?>
and change the link on the main page:
<a href= "Greed_download.php"><h1>Download Greed</h1></a>

the reason for putting path= was so the download.php could be generic for any download you want to offer. but if you wish to only offer 1 might as well keep it simple. and you can always create multiple download phps if there wont be a lot.

let me know how that works ?
julianbury
Forum Newbie
Posts: 3
Joined: Thu Oct 29, 2009 3:25 pm

Re: How to detect downloading from my website

Post by julianbury »

Dear rnoack

That did it !

Thank you so much :D

I can now do the same for the rest of the games.

(-_-) julianbury
Post Reply