PHP - Protect PDF file being access by direct link -


i have pdf file in server, , there php page force download pdf file after credential validation such password validation, if user able know direct link of pdf file manage view/download without go through credential validation.

is there method protect pdf file being access via direct link http://domain.com/mypdf.pdf?

use code...

the best way protect folder htaccess, have mentioned. put pdfs in pdf/ folder, , in same pdf folder put .htaccess file:

rewriteengine on rewriterule .* your-php-script.php 

now no files can accessed url in folder. every request file in folder return your-php-script.php script returns. in your-php-script.php this:-

//check if user has right access file. if no, show access denied , exit script. $path = $_server['request_uri']; $paths = explode('/', path); $lastindex = count($paths) - 1; $filename = $paths[$lastindex]; // maybe add code detect subfolder if have them // check if file exists, if no show error message // output headers here readfile($filename); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -