0

I have implemented a php website that has some users. I want to manage their access to static files.

In addition, I have a function in a file permissions.php that gets a url (e.g. /images/secret.jpg) and checks the it's permission for the current logged in user.

I think I need to add something to .htaccess file that for every request, first call my function in permissions.php then serve the file if it returns true otherwise return 404.

How can I do that?

1 Answer 1

0

One way you can do this is to set the permissions for all the file to be protected, and use PHP to fetch the file and serve it by modifying the headers.. This way, you can check if the user has permission to the file, and if they have, the PHP code will fetch the file and serve it to them.

(Incidentally, there's an answer on the linked question that changes .htaccess. I prefer not mess with that myself).

2
  • Thank you, but how can I realize the requested urls?
    – Mehran
    Oct 10, 2012 at 13:08
  • You can block off direct access, and instead list down all the files that you want to grant access using coding.
    – Extrakun
    Oct 11, 2012 at 7:12

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.