Search code examples
phpfile-permissionsdata-protection

How to protect downloadable files in a remote directory from non-premium users (in php?)


Im building a "premium" section of my site and Im in a need to give download access to files in a remote directly (on a different server), to users with special privileges (accounts stored in mysql db). My site is coded in php/mysql so a php solution would be great.


Solution

  • direct all download links to a php file that'll do all the credential checking.

    you can call the file download.php

    pass along parameters via cookies, get, post, session, or whichever manner you verify privileges.

    once credentials are verified, you can send an appropriate header.

    if it's an image, the header would be header("Content-type: image/jpeg");

    i'm assuming that you also own this remote server.

    some useful links:

    MIME types

    PHP Header Function