title: How to protect php files and download file links
body: <p>I am using below codes to protect direct download links of zip files</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  $filename = $_GET["id"];
  
  $path = "directory/{$filename}.zip";
  
  $mm_type="application/octet-stream"; 
  
  header("Pragma: public");
  
  header("Expires: 0");
  
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  
  header("Cache-Control: public");
  
  header("Content-Description: File Transfer");
  
  header("Content-Type: " . $mm_type);
  
  header("Content-Length: " .(string)(filesize($path)) );
  
  header('Content-Disposition: attachment; filename="'.basename($path).'"');
  
  header("Content-Transfer-Encoding: binary\n");
  
  readfile($path);
  
  exit();
  
  ?&gt;
  </code></pre>
  
  <p>Is the code enough to protect direct download links. I dont want link to be visible via IDM or other download manager.</p>
  
  <p>Now if I dont enter id while calling above php code or enter wring code, server sends php file with some errors stating specified file not found. But that file uncovers the actual location of the file. How to protect php files in such case. Is there anything I can do in htaccess file?</p>
  
  <p>I am newbie in php.
  Thanks</p>