How can I allow only privledged users to download a pdf with php?

Posted by ThinkingInBits on Stack Overflow See other posts from Stack Overflow or by ThinkingInBits
Published on 2010-05-18T15:20:36Z Indexed on 2010/05/18 15:40 UTC
Read the original article Hit count: 198

Filed under:
|
|

Lets say I have some pdf files stored on my server and I only want to allow a person who's paid have access to download a particular pdf.

So for an example, let's say I have a bunch of e-books. The only way a user would be able to download e-book A is if his account contains the right credentials for that particular book.

What's the best way to accomplish this?

Any ideas/advice on how to improve my idea are greatly appreciated!

My current idea:

  • A user places an order

  • Upon success, a new folder would be created by their /account_num/order_id/ A copy of the particular file would be stored in this directory

  • Have php generate an .htaccess that would only allow access from a url that contains a random hash embedded into it.
  • The only way a user would be able to access this random hashed page is if they are signed in as the right user, and the hash matches up with the hash stored in the database, otherwise they are redirected to home page.

© Stack Overflow or respective owner

Related posts about php

Related posts about file-access