title: Multi step form using PHP and sessions
body: <p>I have an administration form which consists of multiple steps, with the possibility to go back and forth. I decided to use sessions because if someone goes back and forth I don't have to worry about sending all the variables, because they are saved in the session.</p>
  
  <p>In the first step, I delete the session if any is available. I do this, because if someone has signed up before and wants to sign up again for somebody else, then all the previous input would be present in the input boxes. So this is the starting page step1.php:</p>
  
  <pre><code>&lt;?php isset($_SESSION))session_destroy(); ?&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
         "http://www.w3.org/TR/html4/strict.dtd"&gt;
  &lt;html&gt;
      &lt;head&gt; ... &lt;/head&gt;
      &lt;body&gt;
      &lt;form  action='step2.php' enctype="multipart/form-data" method='post'&gt; 
      ...
      &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;    
  </code></pre>
  
  <p>Then, I save all input in the $_SESSION array in step2.php:</p>
  
  <pre><code>&lt;?php 
      $_SESSION['var1']=$_POST['var1']
      $_SESSION['var2']=$_POST['var2']   
      ...
  ?&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
         "http://www.w3.org/TR/html4/strict.dtd"&gt;
  &lt;html&gt;
      &lt;head&gt; ... &lt;/head&gt;
      &lt;body&gt;
      &lt;form  action='step3.php' enctype="multipart/form-data" method='post'&gt; 
      ...
      &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;   
  </code></pre>
  
  <p>The problem is, if someone registers and is on page <code>step2.php</code> and accidentally opens <code>step1.php</code> in a new tab, then all saved variables from <code>step1.php</code> <code>($_SESSION['var1'],$_SESSION['var2'],..)</code> are lost.</p>
  
  <p>Is there any possibility to prevent that from happening? </p>