是的,你做得对。但仅限于第一部分(
假设captcha密钥无效,则需要再次下载新的captcha映像并重新验证captcha密匙。如何做到这一点?
我有一个简短的例子,这样做是不是?
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");
}
}
您已经启动了cURL资源($ch(。
因此,您只需要通过cURL_exec($ch(再次执行cURL请求,就会得到一个新页面。cURL_setopt((设置的所有cURL选项都保存在resources中。
这是代码:
if ($page == "Sucess") {
break;
} else {
$page = curl_exec($ch);
//Some curl code here to Re-download Captcha Image (new image)
$data['captchaText'] = CaptchaToText::Scan("images/captcha.jpg");
}