Hi,
For a program download I build a similar counter for a friend of mine. I am not sure whether it was the only way but.. It works in principle, although I seem to remember he did some editing on it. Anyway.. It sghould get you started on hte idea
I had a script which counted for a specified variable the amount of times it was initiated (Like your counter)
After adding the 1 to the count, it would sent header information, but not for a web-page, but for an application, with a force download.
I then linked from my main page, not directly to the file to download, but to the file with this script.
J.
:
$databasedetails = "settings.php"; // Path to the file with database acces settings
error_reporting(0); // Switch this off for debugging!
//print_r($_SESSION);
require($databasedetails); // The file with login settings
mysql_connect($db_host, $db_user, $db_password)
or die ("<b>Couldn't connect to server</b>");
mysql_select_db($db_name)
or die ("<b>Error, no database</b>");
if(isset($_SESSION[loggedin]))
{
If(! isset($_GET[file])) // Kijk of er een bestand gekozen is
{
$file = 0;
}
else
{
$file = $_GET[file];
}
switch ($file)
{
case 1: // Voor elk bestand maak je hier een entry. In de link verwijst file=.. naar deze nummers
$thisfile = "readme.txt";
$download = "true";
break;
case 2:
$thisfile = "readme.exe";
$download = "true";
break;
case 3:
$thisfile = "pdftest.pdf";
$download = "true";
break;
default: // Hier zet je alle leuke dingetjes voor je pagina die te zien moeten zijn!
$body ="
<HTML>
<BODY>
<A HREF=\"download.php?file=1\">Download program 1</A> <br>
<A HREF=\"download.php?file=2\">Download program 2</A> <br>
<A HREF=\"download.php?file=3\">Download program 3</A> <br>
</BODY>
</HTML>";
echo $body;
break;
}
// ---------------------------------------------------------------------------------
// ------------------- Hier gewoon helemaal niets meer aan doen --------------------
// ---------------------------------------------------------------------------------
If($download == "true")
{
// Insert details
$userid = $_SESSION[user_extra] * 100;
$downloadinsert = mysql_query("insert into downloads (D_user, D_file) values ('$userid', '$file') ");
$dbn = "".$thisfile."";
$fp = fopen($dbn, "rb");
$sdata = fread($fp, filesize($dbn));
fclose($fp);
if (strstr($_SERVER["HTTP_USER_AGENT"],"MSIE 5.5"))
{
$att = "";
}
else
{
$att = " attachment;";
}
// $filename = "file.pdf";
header("Cache-control: private"); // fix for IE
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($thisfile));
header("Content-Disposition: attachment;
filename=$thisfile");
$fp = fopen($thisfile, 'r');
fpassthru($fp); // ** CORRECT **
// header('Cache-control: max-age=31536000');
// header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// header('Content-Length: '.filesize($dbn).'');
// header('Content-Type: application/download; name="'.$thisfile.'"');
// header('Content-Disposition:'.$att.' filename="'.$thisfile.'"');
// header('Content-Transfer-Encoding: binary');
// echo $sdata;
// ---------------------------------------------------------------------------------
} // Einde download = 'true'
} // einde "Logged In"