title: Serving download after form submit w/ validation
body: <p>I have created together a pretty simple Download Code redeemer in .php (thanks to help from here) and am having a hard time trying to figure out what the best way to serve a download is if the validation is successful. Basically -</p>
  
  <p>User enters invalid code -> Page is refreshed with error message.
  User enters valid code -> Give download 'Save as' -> refresh page.</p>
  
  <p>At the minute I'm using <a href="http://www.zubrag.com/scripts/download.php" rel="nofollow">http://www.zubrag.com/scripts/download.php</a> to serve the file but once it has started downloading, my form refreshes the page but only half loads the content?!</p>
  
  <p>This is the form with the PHP script I did.</p>
  
  <pre><code>&lt;div class="dcrForm"&gt;
      &lt;p&gt;Have a physical copy of this release? Claim your digital download by entering your Download Code below.&lt;/p&gt;
      &lt;form  action="index.php" method="post"&gt;
          &lt;input type="text" name="code" class="dcrInput" value=""&gt;
          &lt;input type="submit" name="harrisSubmit" class="dcrSubmit" value="Submit"&gt;
      &lt;/form&gt;
  &lt;?php
      include("scripts/dcr_config.php");
      $code="";
      $log="";
  
      if (isset($_POST['harrisSubmit']))
      {
          $code=$_POST['code'];
  
          $link = mysql_connect($hostname, $dbusername, $dbpassword);
          mysql_select_db("$databasename");
  
          $query = "select count from $harris where code='$code'";
          if ($q=mysql_query($query))
              if ($r=mysql_fetch_array($q)){
                  if ($r[0]&lt;3)
                  {
                      $subquery="update $tbname set count='".($r[0]+1)."' where code='$code'";
                      mysql_query($subquery);
                      ?&gt;&lt;script&gt;window.location.href="download.php?f=test.txt";&lt;/script&gt;&lt;?php
                  }
              }
          $log="&lt;p&gt;Invalid code. Try Again.&lt;/p&gt;";
      }
      echo $log."";
  ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Does anyone have an ideas on what the best way to serve the download would be? I know that currently anyone who had the file location could download the file but I'm not sure how I could go about protecting i</p>