One thing you can do is keep all your "secret" files in a directory outside of the server's webroot. All access to these files can then be routed through a single PHP-script inside your directory. Something like this:
http://www.example.com/protected-directory/access.php?file=/foo/document.doc
With a directory structure such as this:
+--+ /server_root
|
+--+ /web_root
| |
| +--+ /protected-directory
| +-- access.php
| +-- access-denied.html
|
+--+ /protected_root
|
+--+ /foo
+-- document.doc
In your access.php
you would do something like this:
$file = $_REQUEST['file'];
if ($user->hasAccessTo($file)) {
readfile("/server_root/protected_root/$file");
} else {
readfile('access-denied.html');
}
Now, you have to be careful that you make sure nobody screws with your file
-parameter and passes something along like "../../../etc/passwd"
. Also, you probably want to make sure you send the correct headers in the above example, I omitted that for reasons of clarity.