Jump to content

[SOLVED] Header Download Plus Page


Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/112535-solved-header-download-plus-page/
Share on other sites

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*/;};

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.

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}

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.

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

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');
}
?>

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.