Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The rewrite rule you have there is fine... except you should probably add a condition to check and make sure the REQUEST is not "handle.php" - otherwise you may get a redirect loop.</p> <p>Now, in your handle.php file - this is handling ALL files request in that folder.</p> <p>In handle.php, you can use <code>$_GET['path']</code> to get the requested file name. While in handle.php, you can include your authentication checks. If the authentication check passes, you can then continue to <code>readfile</code> to the user. An example of handle.php:</p> <pre><code>&lt;?php set_time_limit(0); session_start(); include "../some_functions_auth_file.php"; // NOTE: better file checking should be implemented here. We're using basename() for now. $file = !empty($_GET['path']) ? basename($_GET['path']) : false; if($file === false || !file_exists($file)) die("Invalid file."); if(user_is_authenticated()) { header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false ); header("Pragma: no-cache" ); header("Content-Type: application/octet-stream"); header("Content-Length: " .(string)(filesize($file)) ); header('Content-Disposition: attachment; filename="'.$file.'"'); header("Content-Transfer-Encoding: binary\n"); readfile($file); exit; } else { header("Location: ../login.php"); } ?&gt; </code></pre> <p><em>Note that this is very basic and untested</em></p> <p>Now, if you don't want to use <code>readfile</code> (because it's, well, slow), then perhaps you could set an Apache environment variable... then, while in .htaccess, you could check if that variable exists - and if so, allow the download. Otherwise redirect the user to a login.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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