You can place the PDF outside of the web root directory tree, then have them submit their email via a form input. The form-handler it calls would then process the email address as desired and then serve up the PDF, e.g.:
PHP Code:
<?php
if(!empty($_POST['email'])) {
// save email in DB or whatever you want to do with it
header("Content-Type: application/pdf");
readfile("../path/to/pdf/file.pdf");
exit; // make sure no extraneous bytes get sent
}
else {
// whatever you want to do if email not supplied
}
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
First off, thank you very much for your informative response.
When learning something, it is hard to articulate what exactly you are looking for and what you need help with.
Thank you for your script and not the normal response of "google it or it has already been answered"
Here is what I have:
Code:
<?php
$errors = array();
if(isset($_POST['email']) && !empty($_POST['email']))
{
$_REQUEST['email'] = trim($_REQUEST['email']);
if(substr_count($_POST['email'],"@") != 1 || stristr($_POST['email']," "))
{
$errors[] = "Email address is invalid";
foreach($errors as $value){print "$value<br>";}
exit;
}
// save email in DB or whatever you want to do with it
header("Content-Type: application/pdf");
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile("../files/test.pdf");
exit; // make sure no extraneous bytes get sent
}
else {
// whatever you want to do if email not supplied
exit;
}
?>
I can download the file via the form. However, I can also go via the URL and download the file.
How can I prevent direct access to the PDF, or am I doing something wrong?
Bookmarks