system — 2012-01-18T03:45:51-05:00 — #1
Anyone know if is it possible to password protect an entire directory in PHP so if a user enters the filepath to a word doc/ pdf/excel doc or whatever else in that directory the cannot access it without being logged in?
chris_upjohn — 2012-01-18T04:15:02-05:00 — #2
The most simple way would be to create a RewriteRule in a .htaccess file that looks for the specific URL and takes the user to an authentication page along with the query string appended to the URL, if the user has a current session with the site then grab the download using the query string passed into the RewriteRule.
jakub_polak — 2012-01-18T04:18:33-05:00 — #3
You can solve this in that way, that you put all files that you want to allow only certain users to download outside of web root and then you access the file with PHP script in which you control if the user is or is not logged in.
This problem is discussed on many websites, for example here http://bytes.com/topic/php/answers/758259-displaying-file-not-webroot
webmonkeyottawa — 2012-01-18T10:00:31-05:00 — #4
Create a file in the dir you want to restrict named .htaccesswith only this: deny from all. Now all the content in this folder will be unobtainable. Now create a PHP script to manage authentication (username/password access). When a user is logged in and selects a file to download, use PHP to grab the file and output it. Simple process where you have to send header with the right filetype identified, then just dump the contents of the file.
system — 2012-01-18T10:44:50-05:00 — #5
You couldn't just explain this bit a touch more or point me to where I can find out could you?
"create a PHP script to manage authentication (username/password access). When a user is logged in and selects a file to download, use PHP to grab the file and output it. Simple process"
csu_bill — 2012-01-18T11:09:11-05:00 — #6
If you want a set of login scripts, you can google something like PHP login. I actually started my login scripts with information I found at a blog named New Think Tank.
The login scripts along with MySQL handle the login and authentication. Once you get it working the download part is easy.