title: How to redirect if user did not successfully submit form
body: <p>I have a comments form on my site. After the user submits the form, s/he will be redirected to a "thank you" page. I would prefer that the thank you page only be accessible if one has successfully submitted the form. If the user tries to access the thank you page without first submitting the form, I would like the user to be redirected to the home page. Any suggestions on the best way to do this? </p>
  
  <p>UPDATE: The problem I am having with the solution below is that the user is redirected to the home page even if that user correctly submits the form. </p>
  
  <p>Form page PHP:</p>
  
  <pre><code>&lt;?php
  if (!isset($_SESSION)) {
  session_start();
  
  $_SESSION['sendMessage'] = true;    
  
  }
  </code></pre>
  
  <p>Thank you Page PHP:</p>
  
  <pre><code>&lt;?php
  if (!isset($_SESSION['sendMessage'])) {
  header('Location: http://www.example.com/index.php');
        exit;
  }
  ?&gt;
  </code></pre>