Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best way would be to protect that folder with htaccess, as you have mentioned. So you put all PDFs in pdf/ folder, and in the same pdf folder you out .htaccess file:</p> <pre><code>RewriteEngine on RewriteRule .* your-php-script.php </code></pre> <p>Now no files can be accessed by url in this folder. Every request to every file in this folder will return what your-php-script.php script returns. In your-php-script.php you do something like this:</p> <pre><code>//Check if user has right to access the file. If no, show access denied and exit the script. $path = $_SERVER['REQUEST_URI']; $paths = explode('/', path); $lastIndex = count($paths) - 1; $fileName = $paths[$lastIndex]; // Maybe add some code to detect subfolder if you have them // Check if that file exists, if no show some error message // Output headers here readfile($filename); </code></pre> <p>Now if user opens domain.com/pdf/nsa-secrets.pdf Apache will run your-php-script.php. Script will have variable $_SERVER['REQUEST_URI'] set to "domain.com/pdf/nsa-secrets.pdf". You take the last part (filename) and output it to a user (or not).</p> <p>This will stop anyone from accessing files directly from the internet by knowing URL. If someone has direct access to files on your server, that will not stop them. On the other hand, I think any shared hosting stops users from getting files of other clients. Only way to do it is to hack the server in some way. But then we are getting very paranoid and if that may be a case for you, you shouldn't use shared hosting in the first place.</p> <p>If you cannot make htaccess work, you can try to obfuscate files, so it would be difficult to spot them for someone outside. For example change file from mySecretData.pdf to djjsdmdkjeksm.pdf. This may help a little bit.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload