title: PHP $_SESSION Returning Empty Array Even When Values are Set
body: <p>I'm trying to diagnose a PHP problem.  I'm passing values to a <code>$_SESSION</code> array, and those values are not taken by the array.  I used <code>var_dump($_SESSION)</code> to see what was being returned and I get <code>array (0){}</code>.  This is true even when I know the session is being set and values are being added to the array.</p>
  
  <p>Here's a simplified version of my code (index.php):</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  session_start();
  var_dump($_SESSION); 
  
  if ($_REQUEST['query'] == "" or is_null($_REQUEST['query'])) {
  $errormsg = "You must enter a search term to query.  Please try again.";
  }
  
  ?&gt;
  
  &lt;form name="product_search" id="product_search" method="post" action="index.php"&gt;
  &lt;input size="60" type="text" name="query" id="query" &lt;?php echo "value=\"" .  $_REQUEST['query'] . "\" "; ?&gt;/&gt;
  &lt;?php if (isset($errormsg)) {echo "&lt;span class=\"errormsg\"&gt;" . $errormsg . "&lt;/span&gt;";} ?&gt;
  &lt;input type="submit" class="searchBtn" value="Search"/&gt;
  
  &lt;?php
      $_SESSION['query'] = 'foo';
      $_SESSION['search_field'] = 'man';
      $_SESSION['results'] = 'chu';
  ?&gt;
  
  var_dump($_SESSION); //Will dump array(3) {...}
  </code></pre>
  
  <p>To recreate error:</p>
  
  <ol>
  <li>Load the page.  No problem here; <code>var_dump($_SESSION)</code> at the top returns <code>array(0) {}</code>, which is expected, and the one at the botton returns a three-member array, also as expected.</li>
  <li>Submit the form with something in the query field (to defeat the validation).  Despite the <code>$_SESSION</code> variables being set on the previous page load, the first dump still returns <code>array(0) {}</code>.</li>
  </ol>
  
  <p>I simplified my code here to get at the problem, but I have another page that is returning a $_SESSION variable without difficulty (and the first <code>var_dump</code> produces a one-member array).  Is the problem here that I'm submitting the form to itself, and if so, is there a way other than the <code>$_SESSION</code> array to pass values from one page load to the next?  I've looked at the PHP documentation and searched high and low, but haven't caught anything that's helped.</p>
  
  <p>I should also note that the session ID is the same across page loads, so it appears session state is being maintained from page load to page load.</p>
  
  <p>Thanks in advance for the help.</p>