title: PHP Curl Login Captcha
body: <p>I'm trying to do a curl to use a private webpage after the login, the login form call an action to website/entrar/sair/ with the post vars - login, senha(password), lembrar(remember - cookies), g-recaptcha-response (captcha system) and logar. After a sucessful login the page is redirected to website/private (the page I want to use). The problem is that I dont know what to do with captcha, after I get a sucessful login I get a cookie that is valid for next 24 hours. So what I need to do is, when I access localhost/index.php, it will show the page website/private, if the cookie has expired, it will show the anti captcha from website/entrar/sair/, so I can do a manual verification and get another cookie valid for 24 hours.<br>
  The code I have so far:</p>
  
  <pre><code>$path = $_SERVER["DOCUMENT_ROOT"]."/teste/ctemp";
  $url="http://website.com/entrar/sair/"; 
  $postinfo = "login=xxx&amp;senha=xxx&amp;g-recaptcha-response=xxxx&amp;lembrar=on&amp;logar=";
  $website="http://website.com/private"; 
  
  $cookie_file_path = $path."/cookie.txt";
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_NOBODY, false);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
  
  curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
  curl_setopt($ch, CURLOPT_USERAGENT,
      "Mozilla/5.0 (Windows; U; Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
  
  
  curl_exec($ch);
  
  //page with the content I want to grab
  curl_setopt($ch, CURLOPT_URL, $website);
  
  $html = curl_exec($ch);
  curl_close($ch);
  
  echo $html;  
  </code></pre>
  
  <p>The post form: <a href="http://i.stack.imgur.com/PlfZ9.png" rel="nofollow">Image</a></p>