I'm looking for a way to filter and control access to a folder on a website.
However, what I'd like to do is filter the access requests via PHP and Apache, a little like the way filters are implemented in Java.
So, when a user tries to visit
http://www.mywebsite.example/files/afile.zip
I'd like it first to pass through a PHP script to ensure that the user is not trying to download the same file multiple times, or is doing something else that could break the website.
Is something like this possible? I know it's possible to simply move files above the document root and then serve them that way, but I was looking for something a little more elegant.
Can I use any combination of .htaccess and mod_rewrite to do this?