So I am embedding a PDF file on my page:
<embed src="http://www.mywebsite.com/files/ebook.pdf" width="500" height="375">
Is there anyway to prevent any and all access to that file except for when it is being accessed via this embed?
Thanks!
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.
More elegant way would be to prevent access to that file or better directory from .htaccess file and only allow locally. Then your php script will acss the file when you need it. You can also force download from php.
See this for php example.
And your .htaccess file will look like this and will reside in your restricted directory (where pdf is located):
Last line is your IP address (server) or put simply
Allow from localhostinstead. If somebody else will try to access the directory or files in it, they will be redirected tottp://www.example.com/your-login-page.phpwith status code403(access forbidden). Good Luck