Assume captcha key is invalid, it need to download new captcha image again and re-validate captcha key. How can that be done?
I have include short example, is this the way to do?
while (1) {
$postData = http_build_query($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "\**********************.crt");
curl_setopt($ch, CURLOPT_URL, "https://domain.com/test" . $form_link);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiesPath . "/cookiefile.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiesPath . "/cookiefile.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
//Just a quick example
if ($page == "Sucess") {
break;
} else {
$ch = curl_init();
//Some curl code here to Re-download Captcha Image (new image)
$data['captchaText'] = CaptchaToText::Scan("images/captcha.jpg");
}
}
Yes, you doing it right. But only in the firs part )
You already have cURL resource initiated ($ch).
So you only need to execute cURL request again by curl_exec($ch) and you will get a new page.
All the cURL options set by curl_setopt() are saved in resourse.
Here is the code: