title: PHP Switching between sessions using session_name
body: <p>So I'm trying to write 2 php sessions in the same script, but seems it doesn't work as I thought it will do.</p>
  <p>The code:</p>
  <pre><code>// Start our first session with the name 's1'
  session_name('s1');
  session_start();
  
  $_SESSION['foo'] = 'Foo';
  session_write_close();
  
  // Start our second session with the name 's2'
  session_name('s2');
  session_start();
  
  $_SESSION['foo'] = 'Bar';
  session_write_close();
  
  // We now open our first session and print its value
  session_name('s1');
  session_start();
  
  print_r($_SESSION['foo']);
  </code></pre>
  <p>It prints <code>Bar</code> were afaik it <strong>should</strong> print <code>Foo</code> since we openned session <code>s1</code></p>
  <h3>Question:</h3>
  <p>What is the correct way <em>(I think using session_id is not a safe way of doing this)</em> to make it print <code>Foo</code>?</p>
  <hr />
  <p>Also, if you write something like <code>$_SESSION['color'] = 'red';</code> in session <code>s2</code>, and you go ahead and print the whole <code>s1</code> session, you will see the key <code>color</code> there, it should not be there.</p>
  <p><strong>Am I misusing sessions?</strong></p>