title: Don't allow to resend POST information after reload
body: <p>I have a form that once its submitted the result should not be replicated again by reloading the page, I've tried to assign a random key so that when you reload the page the keys won't match and you won't be able to replicate it but it doesn't work:</p>
  
  <pre><code>$bypass = rand(1,999);
  
  if ($_SERVER['REQUEST_METHOD'] === 'POST'){
      if ($_POST['key'] == $bypass) {
          echo'Hello';
      } else {
          echo "invalid key";
      }
  } else {
      echo '&lt;form action="test.php" method="post"&gt;';
      echo '&lt;input type="hidden" name="key" value="'.$bypass.'" /&gt;&lt;input name="submit" type="submit" value="submit" /&gt;&lt;/form&gt;';
  }
  </code></pre>
  
  <p>The intended function for the code above is to generate a random key that will only work when you submit the form but will now work if you resend the form by reloading the page but it doesn't work as when you submit the form the key will be changed. How can I fix this? </p>