Hi,
I've just settled some code issues with a file download script and now I need to take it to the next level.
I have a list of names and addresses, the query selects say 400 of these and puts them in a .csv file and initatiates a file download. Now, how do I stop the users from pressing refresh and getting another 400 users? They are going to have to pay for it so I don't want them getting as many names and addresses as they want.
Here is the code as I have it:
<?php
mysql_connect(localhost, nn, nn);
mysql_select_db(nn);
$download_me = $_GET['download_me'];
if($download_me) {
$date = date("Ymd");
$name= "$date";
// make browser output downloadable
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$name.csv");
header("Content-Transfer-Encoding: binary");
$result = mysql_query("SELECT id, firstname, lastname, email FROM userstest WHERE registered=1 ORDER BY RAND(id) LIMIT 400");
$formsubmit="1";
while($row = mysql_fetch_object($result)) {
//$query = "DELETE FROM userstest WHERE id=' ".$row->id." ' ";
//print $query;
$array = array(" $row->email, $row->firstname, $row->lastname ");
$line = implode(",", $array) ."\n";
print $line;
//mysql_query ("UPDATE userstest SET registered='2' WHERE id=' ".$row->id." ' ");echo mysql_error();
}
// this stuff is being downloaded; stop here before default stuff is printed
//mysql_query ("DELETE FROM userstest WHERE registered=2");echo mysql_error();
die;
}
if ($formsubmit!="") { $formsubmit="";
printf("<div>You have already downloaded this file!</div>");
} else {
$result = mysql_query("SELECT id, firstname, lastname, email FROM userstest WHERE registered=1 ORDER BY RAND(id) LIMIT 400");
if (mysql_num_rows($result) < 400)
{
printf("<div>Not enough files</div>");
}
else
{
printf('
<div>Click here to <a href=\'?download_me=true\'>download</a> registered users</div>'
);
}
}
?>
Any ideas? I tried putting in a hidden variable $formsubmit and then trying to catch it when they tried again but obviously it's not working as I can refresh as many times as I like.