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!
<?php
include ("../includes/connect.php");
if(!empty($file)){
$ref = $_SERVER["HTTP_REFERER"];
$agent = $_SERVER["HTTP_USER_AGENT"];
$remote = $_SERVER["REMOTE_ADDR"];
$date = time();
$query = "INSERT INTO file_tracker (file, RemoteAddr, agent, ref, date) VALUES ('$file', '$remote','$agent','$ref', '$date')";
$result = mysql_query($query) or die (mysql_error());
header("Location:$file");
}
?>
What I am wondering is if there is a way to verify that the file has been downloaded before I add the information to the database. Currently it does it when the download dialogue comes up. So, this creates spam clicking and inflated download counts. Any help on how to get a "true" count of downloads of specific files? Thanks!
Your php should sent specific headers and file content (ofcourse make record in DB before this). See http://php.net/manual/en/function.readfile.php - in user cntributed notes have a simple example.
Ok, well I can't say that I have run into that header issue before, but I have been taking a look at that thread and others. I am still confused on how I go about and fix the following 2 issues:
1) Get the header() issue fixed for IE (I have read the post you suggested and I am soo confused)
2) Check to see if the file has been completely downloaded before posting the information to the DB. (I tried the readfile() as suggested above, but no luck... I might be doing it wrong).
And to PaTTeR, this is the beginning of a script to serve files for my site. So, it is just a work in progress. Thanks for all your help so far!
I still have the same code as my 1st post since I am confused on what to do next.