1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Rep Power

    Prevent direct file access but enable it from a link

    Hi everyone, my title may seem weird, but here's some details about what I'm trying to achieve and if it's possible.

    I have a PHP file, let's say page.php, that I let users authenticate and I use sessions to manage their authentication, so only authenticated people can see what's inside that page.

    On that page, there's a link, a simple link, that opens a PDF file on a separate window. So that PDF is 'protected' in a way, sort of.

    But as you can see, it's not 'really' protected, someone who would have the exact URL of the PDF file could copy-paste it and access the file directly.

    What I want to achieve is let people who are authenticated click on the link and open the PDF file on a separate window BUT prevent the PDF from being accessed directly from it's URL.

    I want to prevent direct access to those PDF from people directly typing or copying the address without having clicked on the link when authenticated.

    I know it's possible for an included file, but a separate PDF, is it?

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Rep Power
    Instead of a simple link use a link to another page that outputs the PDF file using headers. Re-verify the authentication on that page but make sure you do not output anything (not even white space) before the headers.

    PHP Code:


    Last edited by gw1500se; September 5th, 2017 at 09:00 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Rep Power
    Search in Google for this and you will find what you need: php protect download pdf

IMN logo majestic logo threadwatch logo seochat tools logo