944,172 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1783
  • PHP RSS
Oct 8th, 2009
-1

Force users to fill out form before file download

Expand Post »
Hello,

I need to have users fill out a form before they are granted to download any given file to generate sales leads. I do have a script which was custom made but am having some issues with it.

I am wondering if anyone knows of a service (or script) that does this. I am baffled on my long search on Google that I haven't found anything like this!

Thank you for any suggestions!

Mark
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Markstein is offline Offline
2 posts
since Jan 2008
Oct 8th, 2009
-2
Re: Force users to fill out form before file download
Are you talking about a login form? What's the model you're looking for? The complexity/access rights/file persistence may determine the solution that will fit your needs.

Redirects are a relatively simple method, which only occur if form data is verified. However this simple solution may not be suitable if you want to 'cloak' the origin of the folder/file.

Giving the filename an obscure name (e.g. a hashed name) can deter users from guessing other filenames from the same folder.

I'm sure there are loads of other solutions to this; some of them extremely sophisticated - however, these may an overkill.

I came across a discussion here:

http://www.reddit.com/r/PHP/comments...s_to_restrict/

For some reason Content-Disposition header is frowned upon.
Sponsor
Featured Poster
Reputation Points: 1067
Solved Threads: 955
Disgraced Poster
ardav is offline Offline
6,728 posts
since Oct 2006
Oct 8th, 2009
-1
Re: Force users to fill out form before file download
Hey Ardav thanks for the response!

Basically what I have is some whitepapers and brochures for people (the public) to download. Basically before they are allowed to download a file they must fill out a form which asks them for their name, company, email, phone number etc. The information is stored in a database. This way I know who is downloading what file and gain potential sales leads.

Once they fill out the form they are redirected to a "thankyou" page which prompts a save as dialog and dishes out the file.

If they wish to download another file they repeat the process.

I have the files outside of the public root so they are not directly accessible.

I'm just wondering if there are any scripts out there that accomplish this or possibly an online service. Honestly I am shocked that I haven't been able to find a script that does this for a non-membership site.

Have you heard of such a script?

Thanks a lot,

Mark
Last edited by Markstein; Oct 8th, 2009 at 6:53 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Markstein is offline Offline
2 posts
since Jan 2008
Oct 8th, 2009
1
Re: Force users to fill out form before file download
Where the file is accessed by
html Syntax (Toggle Plain Text)
  1. <a href='download.php?file=thisfile.pdf'>download Thisfile.pdf</a>

mysql
php Syntax (Toggle Plain Text)
  1. <?php /*download.php*/
  2. If (!$_POST['file']='') {
  3. /* validate $_POST any amount of form validation this is just an exercise
  4. or die('invalid information'); */
  5. $con=mysql_connect("server","user","password");
  6. if (!$con) { die('Could not connect: '.mysql_error()); }
  7. mysql_select_db("my_db", $con);
  8. mysql_query("INSERT INTO downloads (FirstName, LastName, Company, email, telephone, file) VALUES ('$_POST['Firstname']', '$_POST['Lastname']', '$_POST['Company']', '$_POST['email']', '$_POST[telephone]', '$_POST['file']')");
  9. $path=''; //full path outside the root to downloadable files
  10. header("Content-disposition: attachment; filename=$_POST['file']");
  11. header('Content-type: application/pdf;');
  12. readfile("$path$_POST['file']"); }
  13. else {echo '<form action="'.$_SERVER['php_self'].'" method="post">';
  14. .'<input name="file" type="hidden" value="'.$file.'">';
  15. .'Firstname ?<input name="Firstname" type="text"><br>';
  16. .'lastname ?<input name="Lastname" type="text"><br>';
  17. .'Company ?<input name="Company" type="text"><br>';
  18. .'email ?<input name="email" type="text"><br>';
  19. .'telephone ?<input name="telephone" type="text"><br>';
  20. .'<input name="go" type="submit" Value="Download file"></form>'; }
  21. ?>
csv text file
php Syntax (Toggle Plain Text)
  1. <?php <?php /*download.php*/
  2. If (!$_POST['file']='') {
  3. /* validate $_POST any amount of form validation this is just an exercise
  4. or die('invalid information'); */
  5. $file = "./logfiles/logfile.csv";// define the text file, named as .csv excell can open it.
  6. $fp = fopen($file, "a+");//open the text file for writing.
  7. fputs ($fp, "$_POST['Firstname'],$_POST['Lastname'],$_POST['Company'],$_POST['email'],$_POST[telephone],$_POST['file']\n");
  8. fclose($fp);
  9. $path=''; //full path outside the root to downloadable files
  10. header("Content-disposition: attachment; filename=$_POST['file']");
  11. header('Content-type: application/pdf;');
  12. readfile("$path$_POST['file']"); }
  13. else {echo '<form action="'.$_SERVER['php_self'].'" method="post">';
  14. .'<input name="file" type="hidden" value="'.$file.'">';
  15. .'Firstname ?<input name="Firstname" type="text"><br>';
  16. .'lastname ?<input name="Lastname" type="text"><br>';
  17. .'Company ?<input name="Company" type="text"><br>';
  18. .'email ?<input name="email" type="text"><br>';
  19. .'telephone ?<input name="telephone" type="text"><br>';
  20. .'<input name="go" type="submit" Value="Download file"></form>'; }
  21. ?>
Last edited by almostbob; Oct 8th, 2009 at 8:03 pm.
Reputation Points: 562
Solved Threads: 369
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Oct 9th, 2009
-1
Re: Force users to fill out form before file download
The file download form the server to the client machine will be done by the php, but before that restricting the user in some way or the client side validation will help to achieve what you want exactly with the javascript.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: resize help
Next Thread in PHP Forum Timeline: How to Import excel data to mysql database?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC