title: How can I get SoapClient to respect a session?
body: <p>I am working with a SOAP API for an e-commerce shopping cart and I can't seem to be able to get the session to persist through different pages.</p>
  
  <p>As an example, I have some test code below (with a bunch of debug messages) which adds an item to the cart and then views the cart.  When I run this in my browser it works perfectly, but if I refresh the page, I am expecting there to then be two items in the cart (one from each of the two page calls).  However, it doesn't seem to remember anything from previous calls to the page.  I know the API is working because if I just call "AddToCart" twice on this page and then call "GetCartContents" I see the 2 items in the cart correctly.</p>
  
  <p>Am I missing something?</p>
  
  <pre><code>&lt;?php 
  session_start();
  
  $url = "https://www.example.com/soap-checkout.php?wsdl";
  $client = new SoapClient($url, array("trace" =&gt; 1, "exception" =&gt; 0));
  
  if (!empty($_SESSION['soapcookies'])) {
      foreach($_SESSION['soapcookies'] AS $name=&gt;$value) {
          if (is_array($value)) {
              foreach($value AS $k=&gt;$v) {
                  $client-&gt;__setCookie($name[$k], $v);
              }
          } else {
              $client-&gt;__setCookie($name, $value);
          }
      }
  }
  echo "&lt;pre style='background: grey;'&gt;browser cookies: ".print_r($_COOKIE, true)."&lt;/pre&gt;";//debug
  
  // Add to Cart
  $data = array( 
      "domain" =&gt; 'www.example.net', 
      "sku"    =&gt; "1234",
      "qty"    =&gt; 1
  );
  $result = $client-&gt;__soapCall("AddToCart", $data);
  $responseHeader = $client-&gt;__getLastResponseHeaders();//debug
  echo "&lt;pre style='background: purple;'&gt;responseHeader: ".print_r($responseHeader, true)."&lt;/pre&gt;";//debug
  echo "&lt;pre style='background: grey;'&gt;cookies: ".print_r($client-&gt;_cookies, true)."&lt;/pre&gt;";//debug
  echo "&lt;pre style='background: yellow;'&gt;Result of 'AddToCart': ".print_r($result, true)."&lt;/pre&gt;";//debug
  
  // Set SOAP Cookies in PHP Session
  $_SESSION['soapcookies'] = $client-&gt;_cookies;
  
  // View Cart
  $data = array(
      "domain" =&gt; 'www.example.net'
  );
  $result = $client-&gt;__soapCall("GetCartContents", $data);
  echo "&lt;pre style='background: skyblue;'&gt;Result of 'GetCartContents': ".print_r($result, true)."&lt;/pre&gt;";//debug
  ?&gt;
  </code></pre>
  
  <p>FYI, the PHP version is 5.2.6</p>