title: PHP -> SOAP -> Magento Webservice: get Cookies set by Magento
body: <p>I am new to Magento Web-Service and have to expand it.
  The Webservice shell be able to login an customer, give me the session cookie back so that I can redirect to a file that sets the cookie again, redirects me and I can see my cart and proceed to checkout on the Magento Store.</p>
  
  <p>The Problem:
  Magento creates a cookie (that contains the session id or whatever, ive tried to set this cookie manual and them im logged in) instead of setting a session when the customer logs in.
  I've tried now for several hours to get this cookie that is set by magento in my magento web-service. It seems the cookie isn't set when i call</p>
  
  <pre><code>$session = Mage::getSingleton('customer/session');
  return $session-&gt;getCookie()-&gt;get('frontend');
  </code></pre>
  
  <p>Heres my complete Code:
  Magento Webservice Api:</p>
  
  <pre><code>&lt;?php 
  class Customapi_Model_Core_Api
  {
  
  public function __construct()
  {
  }
  
  public function checkout($user, $cart)
  {
      $ret['cookie'] = $this-&gt;login($user);
  
      //$coreCookie = Mage::getSingleton('core/cookie');
      //$ret['cookie'] = $_COOKIE['frontend'];
      return $ret;
  }
  
  function login($user)
  {
      Mage::getSingleton('core/session', array('name'=&gt;'frontend'));
      $session = Mage::getSingleton('customer/session');
      try
      {
          $session-&gt;loginById($user['id']);
      }
      catch (Exception $e)
      {
      }
      return $session-&gt;getCookie()-&gt;get('frontend');
  }
  
  }
  ?&gt;
  </code></pre>
  
  <p>Heres my Api Call in Php:</p>
  
  <pre><code>&lt;?php
  $teambook_path = 'http://localhost/magento/';
  
  $soap = new SoapClient('http://localhost/magento/api/?wsdl');
  $soap-&gt;startSession();
  $sessionId = $soap-&gt;login('ApiUser', 'ApiKey');
  
  $userSession = $soap-&gt;call(
      $sessionId,
      'customapi.checkout',
      array(
          array(
              'id' =&gt; 1,
              'username' =&gt; 'Ruf_Michael@gmx.de',
              'password' =&gt; '***'
          ),
          array(
          )
      )
  );
  
  echo '&lt;pre&gt;';
  var_dump($userSession)."\n";
  if(isset($userSession['sid']))
      echo '&lt;a href="'.$teambook_path.'session.php?sid='.$userSession['sid'].'" target="_blank"&gt;'.$userSession['sid'].'&lt;/a&gt;'."\n";
  echo '&lt;/pre&gt;';
  
  $soap-&gt;endSession($sessionId);
  ?&gt;
  </code></pre>
  
  <p>Thanks for every help!
  MRu</p>
  
  <hr>
  
  <p>Sorry i am writing an answer but the comment box denied me to write more than ... letters.</p>
  
  <p>I've tried both codes you posted and all I get is an empty Array or Bool false.
  I wrote a static function:</p>
  
  <pre><code>private static $cookie = array();
  public static function cookie($key, $value)
  {
      if($key == 'frontend') {
          self::$cookie['key']   = $key;
          self::$cookie['value'] = $value;
      }
  }
  </code></pre>
  
  <p>that is called in Mage_Core_Model_Session_Abstract_Varien::start and I got the frontend cookie value:</p>
  
  <pre><code>Customapi_Model_Core_Api::cookie($sessionName, $this-&gt;getSessionId());
  </code></pre>
  
  <p>in line 125.</p>
  
  <p>But that didnt solve my basic Problem:
  The Session created in the Api call can't be restored, although it is set to the correct value.</p>
  
  <p>Thanks for your help!</p>