title: Scrape Magento website which uses Cookies for "Add to cart"
body: <p>I am scraping <a href="http://www.beautyinzone.net/etude-chocolate-kiss-perfumed-lip-set.html" rel="nofollow">this URL</a>.</p>
  
  <p>I want to scrape quantity of this item. </p>
  
  <p>For that, my strategy is that I will try to add quantity and POST the form until an error appears saying that <strong>"The amount required for "xyz product" is not enough."</strong></p>
  
  <p>I have tried posting FORM with <code>file_get_contents();</code> and <code>echo</code> the output, it returns an error page saying that <em><code>Cookies must be enabled in your browser</code></em></p>
  
  <p>Here is how I am posting</p>
  
  <pre><code>    $postdata = http_build_query(
              array(
                  'product' =&gt; $prod_id,
                  'qty' =&gt; 5,
                  'related_product' =&gt; ''
              )
      );
  
      $opts = array('http' =&gt;
          array(
              'method' =&gt; 'POST',
              'header' =&gt; 'Content-type: application/x-www-form-urlencoded',
              'content' =&gt; $postdata
          )
      );
  
      $context = stream_context_create($opts);
  
      $result = file_get_contents($action_url, false, $context);
  </code></pre>
  
  <p>I have also tried <code>cURL</code> with </p>
  
  <p>$cookieFile = tempnam(null, 'SMS');
          $userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0';</p>
  
  <pre><code>    $cookieFile = tempnam(null, 'SMS');
      $userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0';
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $action_url);
  
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
      curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
      $post = array(
          'product' =&gt; $prod_id,
          'qty' =&gt; 5,
          'related_product' =&gt; '');
  
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
      $html = curl_exec($ch);
  </code></pre>
  
  <p>But still I get error from that site that Cookies should be enabled in browser.</p>
  
  <p><strong>So my question is how I can add product to cart using PHP?</strong></p>