title: How to retrieve captcha and save session with PHP cURL?
body: <p>UPDATE: SOLVED</p>
  
  <blockquote>
    <p>Hi all, i've got it, just save cookie
    to temp file, and resubmit form with
    curl and set cookies with previous
    temp file :) thanks all for respond :)</p>
  </blockquote>
  
  <p>This my working code</p>
  
  <pre><code>$ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url_register);  
          curl_setopt($ch, CURLOPT_USERAGENT, $this-&gt;useragent);
          curl_setopt($ch, CURLOPT_COOKIEJAR, $this-&gt;cookie); 
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);    
          $out['result']  = curl_exec($ch); 
          $out['error']   = curl_error($ch);
          $out['info']    = curl_getinfo($ch);
          curl_close($ch);
  </code></pre>
  
  <p>And for next curl just use <strong>CURLOPT_COOKIEFILE</strong> like this</p>
  
  <pre><code>/* fetch captcha url with existed cookie */
              $ch = curl_init($captcha_url);
              curl_setopt($ch, CURLOPT_USERAGENT, $this-&gt;useragent);
              curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
              curl_setopt($ch, CURLOPT_COOKIEFILE, $this-&gt;cookie); 
              curl_setopt($ch, CURLOPT_FILE, $fp); 
              $out2['result'] = curl_exec($ch);
              $out2['error']  = curl_error($ch);
              $out2['info']   = curl_getinfo($ch);
              curl_close($ch);
  </code></pre>
  
  <p>Hi all, </p>
  
  <p>i'm create some script to submit content via php curl. first fetch session and captcha, and user must submit captcha to final submit.</p>
  
  <p>the problem is i can't get captcha, i've try with this code and preg_match to get image tag and return it</p>
  
  <pre><code>    $ch = curl_init();
  
   curl_setopt($ch, CURLOPT_URL,$url);  
   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_COOKIE, 1);
   curl_setopt($ch, CURLOPT_COOKIEJAR, "1");
   curl_setopt($ch, CURLOPT_COOKIEFILE, "1");
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);    
      $result = curl_exec($ch);  
      curl_close($ch);
  </code></pre>
  
  <p>But no luck, page i'm trying to submit is <a href="http://abadijayaiklan.co.cc/pasang-iklan/" rel="nofollow noreferrer">http://abadijayaiklan.co.cc/pasang-iklan/</a>.</p>
  
  <p>I hope someone can help me out :)</p>
  
  <p>Thanks and regards</p>