0

I'm currently creating a website and i'm bloked on a point.

In fact, i have a folder with a lot of PDF files. I would like to restict the access to this files according to the database but i don't know how to do it.

Example : A user Marcel go to the website, he log himself and if he has credits ( mysql variable in the database), he can download one file prealably chosen. If he doesn't have credit, access is forbidden.

I thought about using an .htaccess file but i'm not sure if it's the best solution.

I really need your point of view.

Thks a lot

I found the solution with your help, here is my code : THks a lot

 

$file='TP/'.$_GET['download'].'.pdf'; $filename=$_GET['download'].'.pdf'; header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file)); header('Accept-Ranges: bytes'); @readfile($file);

2
  • While it is possible to do this with plain apache mods (mod_auth_mysql), I'd configure the apache server to not serve those files at all, and use PHP (or any other server-side language, be it some simple CGI script) to check authorization and, if granted, read and output the files. Nov 13, 2013 at 19:54
  • Oki, thks you i´will see solution this evening. Nov 14, 2013 at 7:10

1 Answer 1

0

Folder protection can be done with .htaccess, .htpasswd

see: http://www.elated.com/articles/password-protecting-your-pages-with-htaccess/

The htpasswd can contain 1 user and password or a whole list. So each users could have individual credentials, but all would see the same files. Which is ok for some scenarios, other scenarios need individual file lists. However the credentials are not stored in the DB. If that is necessary try the solution from the comment above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.