I am having one manual in PDF file on root folder. Currently, when I access this manual directly like http://www.mysite.com/mymanual.pdf it gets opened directly, what I want is when I access this url, instead of getting opened, it should get redirect to login page and when I logged in with the system, then manual should get opened.
This behaviour should be only when the user is not logged in. If the user is logged in and tries to access the manual, it should get opened.
Please help me. Your help will be highly appreciated.
Youd have to set a session cookie using javescript once the client has logged in.
Then use use .htaccess to check for that cookie before allowing access to the file(s) your protecting.
Ralphs idea of just locking down the folder was my first thought, but then your users would need to enter a username and password to get in the directory regardless of whether they are already locked in or not.
The .htaccess route is more comprehensive BUT very much more complicated and if you arent familiar with rewrite rules etc, perhaps Ralph’s idea is the one you should go with at this time.
Or… you could do what most PHP-download sites do, and never directly link someone to the file, use a PHP page to output the contents, and redirect if they’re not logged in, which is what tom is showing you how to do
Originally I tried to do it using only .htaccess but could not come up with a good solution. Then I used your suggestion and came up with that so that is really yours.
The way this should be handled is as tom6 and StarLion suggested with the modification of storing the file itself outside of http access. That way it can never be accessed directly though http only indirectly through a script that can control access privileges.