title: How to login in with Curl and SSL and cookies
body: <p>I been trying to log into barnesandnoble.com mobile site with curl
  and have had no luck so far.  I get back the page with no errors
  and it defaults my email into the email input form box of the login page again (in the form returned from print $result).</p>
  
  <p>The same code can actually let me go into ebay correctly
  by changing the LOGINURL to point to ebay's login</p>
  
  <p>The only difference being that barnesandnobles is https://
  and ebay login was http://</p>
  
  <p>Also, I believe that barnes website is asp/aspx so I don't know
  how that would handle cookies and _state differently</p>
  
  <p>Any help would be appreciated as I been trying to debug this for the
  past 16hrs</p>
  
  <p>also, my cookie.txt is writable and working</p>
  
  <pre><code>&lt;?php
      $cookie_file_path = "C:/test/cookie.txt";
      $LOGINURL = "https://cart2.barnesandnoble.com/mobileacct/op.asp?stage=signIn"; 
      $agent = "Nokia-Communicator-WWW-Browser/2.0 (Geos 3.0 Nokia-9000i)";
  
      $ch = curl_init(); 
  
      $headers[] = "Accept: */*";
      $headers[] = "Connection: Keep-Alive";
      $headers[] = "Content-type: application/x-www-form-urlencoded;charset=UTF-8";
  
      curl_setopt($ch, CURLOPT_HTTPHEADER,  $headers);
      curl_setopt($ch, CURLOPT_HEADER,  0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_URL, $LOGINURL);
      curl_setopt($ch, CURLOPT_USERAGENT, $agent);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
  
      $content = curl_exec($ch); 
  
      curl_close($ch); 
  
      unset($ch); 
  
      // NAME="path_state" value="6657403"&gt;
  
      if(stristr($content,"path_state")){
          $array1 = explode('path_state" value="',$content);
          $content1 = $array1[1];
          $array2 = explode('"&gt;',$content1);
          $content2 = $array2[0];
      }
  
      $LOGINURL = "https://cart2.barnesandnoble.com/mobileacct/op.asp?stage=signIn";
      $POSTFIELDS = "d_hidPageStamp=V_3_17&amp;hidViewMode=opSignIn&amp;stage=signIn&amp;previousStage=mainStage&amp;path_state=" .  $content2 . "&amp;emailAddress=YOUREMAILHERE@gmail.com&amp;acctPassword=YOURPASSWORD";
      $reffer = "https://cart2.barnesandnoble.com/mobileacct/op.asp?stage=signIn"; 
  
      $ch = curl_init(); 
  
      $headers[] = "Accept: */*";
      $headers[] = "Connection: Keep-Alive";
      $headers[] = "Content-type: application/x-www-form-urlencoded;charset=UTF-8";
  
      curl_setopt($ch, CURLOPT_HTTPHEADER,  $headers);
      curl_setopt($ch, CURLOPT_HEADER,  0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);   
      curl_setopt($ch, CURLOPT_URL, $LOGINURL); 
      curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
      curl_setopt($ch, CURLOPT_POST, 1); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
      curl_setopt($ch, CURLOPT_REFERER, $reffer); 
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
  
      $result = curl_exec($ch);  
  
      print $result; 
  ?&gt;
  </code></pre>