Jump to content

Download File after Authentication


Alexandru_mbm

Recommended Posts

Hello to you all!

 

This is my first post on this big big forum! Nice one!

 

Let's go directly to the problem...

 

I have an website that has few informations about a process or a product.

In this page there is an PDF file that has the hole description and details about that process or product.

 

All i want is that the visitors to register into my website and after that thei can download any PDF file (or other) as much as thei want.

 

 

I have found some samples on the internet but is only for authentication not for download too.

 

Anyone can help me with this problem ? Please!!!

 

(sorry for my bad english)

Link to comment
Share on other sites

you can link to the download as download.php?file=1 and then in that you can have:

 

$registered = $_SESSION['logged_in']?true:false; // replace with actual login sequence data
if(!$registered)
    die("message to be displayed if not registered");

$fileid = $_GET['file'];
switch($fileid)
{
case 1: $file = "somefile1.pdf"; break;
case 1: $file = "somefile2.pdf"; break; // ...etc
default: die("message if file does not exist"); break; // if file ID is not in switch
}
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment; filename=\"".basename($file)."\"");
readfile($file);

(untested but should work)

Link to comment
Share on other sites

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.