Php 在验证码成功之前循环?

Php 在验证码成功之前循环?,php,curl,captcha,Php,Curl,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_seto

假设验证码密钥无效,它需要再次下载新的验证码图像并重新验证验证码密钥。如何做到这一点

我有一个简短的例子,是这样做的吗

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选项都保存在resource中

代码如下:

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");
}

这与垃圾邮件无关!为什么在else子句中使用第二个curl_init?卷曲句柄可以重复使用,因此无需每次迭代都初始化一个新的卷曲句柄,更不用说两个卷曲句柄,其中一个会立即被第二个卷曲句柄破坏。根据定义,您无法自动解决验证码-否则,它就不会是一个
完全自动化的公共图灵测试来区分计算机和人类
@Marc B,啊,说得好。。所以我走对了路?如果验证码无效,然后将反复循环,直到
$page==“success”
@phihag,然后需要更新定义。验证码已经被破坏了很长一段时间(更不用说有大量的服务让呼叫中心的许多人通过这些API来填写它们)。