title: Prevent Download Via URL
body: <p>I currently have a PHP file asks you to login using a MySQL database. Once logged in, 3 links appear allowing me to download files. Although, if I access the file directly it will download without having to login. How would I prevent people from downloading via the URL bar, but still allow JavaScript to download the file?</p>
  
  <p>If this isn't possible, is there something else I can do to allow download? For example, using PHP to download instead of JavaScript? I know JavaScript is client side, so I wonder if that will prevent it from accessing the download.</p>
  
  <p>I can't really give much code, but here is the JavaScript that downloads it. The link basically calls the downloadLink function;</p>
  
  <pre><code>    var downloadURL = function downloadURL(url) {
       cLog("STDOUT: Attempting Download Of File: "+url);
      var hiddenIFrameID = 'hiddenDownloader',
          iframe = document.getElementById(hiddenIFrameID);
      if (iframe === null) {
          iframe = document.createElement('iframe');
          iframe.id = hiddenIFrameID;
          iframe.style.display = 'none';
          document.body.appendChild(iframe);
      }
      iframe.src = url;
  };
  
  function downloadLink(fileLink) {
      if (fileLink) {
           cLog("STDOUT: File Link: "+fileLink);
          downloadURL("/DownloadAssets/"+fileLink);
           cLog("STDOUT: Function Finish, File Should Be Queded");
      } else {
           cLog("ERROR: No File Link");   
      }
  }
  </code></pre>