views:

34

answers:

1

Hi there,

I have a set of files in a secure directory (currently secured by .htaccess, only 'the site' can access these files).

The files should only be available to members of the site; when they are logged in. I did have links in the members' area which went to a secure download script - however, using the readfile() function caused problems with the files across Browser/OS ie. losing line endings, corrupt PDFs.

So, I thought a better way might be to only allow people who have clicked the link (within the site) to access the files - hence they have to be logged in as a member. Going ditectly to the resource with it's URL would forward to a 403 forbidden page.

My .htaccess skills aren't the best, but I thought the concept would be similar to stopping hotlinking of images?

Any help - and knowing whether this is possible - would be greatly appreciated.

Best Regards,

Rich

+1  A: 

What kind of login/authentication are you using? If you're using the regular HTTP auth stuff, you can just place those directives into the .htaccess along with

Require valid-user

which would allow access only to those who've succesfully logged in. If it's session based, you'll have to fix up the intermediary PHP script, as Apache knows nothing of PHP sessions. At most it can check for the presence/content of a cookie, but then you'd be trusting the clien to not mess with the cookie's conents.

Marc B
I'm not using HTTP auth, the login is handled by PHP. I had a secure script delivering the files, the problem with this was that due to readfile() and how it works, text files would lose their line endings when opened in notepad, which is unacceptable. Thanks :)
Rich
Might want to check how the file was being served up. PHP itself wouldn't translate the file from (say) utf-8 into latin1 or whatever. But if you're serving up a different charset and/or content header, then the browser is free to translate as it sees fit.
Marc B