【发布时间】:2012-12-19 03:10:12
【问题描述】:
假设验证码无效,需要重新下载新的验证码图片并重新验证验证码。怎么可能?
我有包含简短的例子,这是这样做的吗?
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");
}
}
【问题讨论】:
-
与垃圾邮件无关!
-
为什么 else 子句中有第二个 curl_init ?卷曲句柄可以重复使用,因此无需每次迭代都初始化一个新的,更不用说两个了,其中一个会立即被第二个丢弃。
-
根据定义,您不能自动解决验证码 - 否则,它不会是
Completely Automated Public Turing test to tell Computers and Humans Apart。 -
@Marc B,好点.. 所以我走在正确的道路上?如果验证码无效,则将一次又一次循环,直到
$page == "Sucess" -
@phihag 定义需要更新。验证码已经被破坏了很长时间(更不用说呼叫中心有大量的服务让很多人通过这些 API 填写它们)。