Guest Posted June 30, 2008 Share Posted June 30, 2008 I want to make a download section but I am afraid of people directly linking to the file itself wich wouldnt allow me to show any ads along the way wich means -$. I was looking into how sourceforge does there download system and they just directly link to the file through a iframe and then I could check the refferer but I was wonder if I could use the http headers to do this. Maybe like send out the file and then the page so that way they get there file and they have to view the page as well. Is that possible if so do you know how? Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/ Share on other sites More sharing options...
aeonsky Posted June 30, 2008 Share Posted June 30, 2008 I don't know how u wanna do this, but you can do this with one page or seperate pages if you like: My strategy for one page. 1. User looks at a page (no vars set). 2. User clicks a link to download (step 2). They view the ad. Click the link to step=3. 3. User arrives at step=3 and downloads file. The easiest way to do this is to do this: if ($_SERVER['REQUEST_URI'] == "/".$_SERVER['PHP_SELF']."?step=2") {/*header code to introduce the download file*/;}; Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-577867 Share on other sites More sharing options...
Guest Posted June 30, 2008 Share Posted June 30, 2008 I like your method that would do it exactly. What I got out of it they can link directly to it but the php would sense the variable is not set so it would show them the page with the ads then they can click on somthing like continue to download and boom variable set and the file will begin downloading. I was just about to go to bed but now... lol Thank you so much. Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-577870 Share on other sites More sharing options...
aeonsky Posted June 30, 2008 Share Posted June 30, 2008 You're welcome. Here is something more complete... It is for a zip file! index.php contains a link to download ad page <a href="index.php?page=2">Link</a> index.php?step=2 show ads contains a link to download page<a href="index.php?page=3">Link</a> index.php?step=3 if ($_SERVER['REQUEST_URI'] == "/".$_SERVER['PHP_SELF']."?step=2") { header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"file.zip\""); ;} else {echo "No hotlinking!";}; And to check what step it is, use just if $step = 1 {blah} if $step = 2 {blah2} if $step = 3 {blah3} Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-577873 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Share Posted June 30, 2008 but once a user figures this out, they could just type in the address bar: index.php?page=3 you need to encrypt the last part after the ? so you could get something like: index.php?a45dfa56f4a65d4d7 but then they could just copy the link and paste around forums across the internet. idk. Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-577918 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 <?php $_GET['step'] = $_GET['step'].md5("salt"); Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-577927 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Share Posted June 30, 2008 wait I got it, you could have a hidden value, then do a if statement with a isset on the next page so somthing like this on page 3 if(isset($_POST['view'])){ echo "<a href=\"file.zip\">click here</a> to download"; }else{ Location: "index.php?page=2"; } man I think I got this Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-577950 Share on other sites More sharing options...
Guest Posted June 30, 2008 Share Posted June 30, 2008 What I did was I made a session variable on the first page with the ads then on the second page where you actually download the file it checks that session variable if its not set it will redirect you to the first page then you have to click continue to download. Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-577957 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Share Posted June 30, 2008 here you can see what I was trying to say here: http://lamezz.info/pg.php now try to goto http://lamezz.info/page.php first. here is the code: pg.php: <form id="form1" name="form1" method="post" action="page.php"> <label> <input type="submit" name="value" id="value" value="Continue" /> </label> </form> page.php <?php if(isset($_POST['value'])){ echo "Welcome to Page 2"; }else{ header('Location: pg.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-577966 Share on other sites More sharing options...
aeonsky Posted June 30, 2008 Share Posted June 30, 2008 but once a user figures this out, they could just type in the address bar: index.php?page=3 That is the whole point of the code I showed... if ($_SERVER['REQUEST_URI'] == "/".$_SERVER['PHP_SELF']."?step=2") { This line prevents user from entering index.php?step=3 because it checks the referrer. The user must have came from ?step=2 Quote Link to comment https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/#findComment-578270 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.