I have a download folder.
So is it possible to redirect a user to a login page when he/she tries to download any of the files from the download folder.
I have heard this can be achieved using .htaccess, but I can’t find a good tutorial.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
htaccess will be activated before the PHP engine. Hence you can’t use this system when you need to check if a user is logged in or not.
The way to do this is to send only logged in users to a page containing a file list for download, and when pressing the link PHP will do the actual downloading of the file to the client, using the right headers.
Example from php.net
The actual files you should put outside the public folders, so no danger of users surfing directly to them.