thiagocavaloti / recaptcha

Automatically exported from code.google.com/p/recaptcha
0 stars 0 forks source link

_recaptcha_http_post fails when it hits a proxy #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Enable proxy mine is http://proxy:8083
2. Make the reCaptcha pages
3. Try to validate

What is the expected output? What do you see instead?
I get an error stating that "fsockopen() [<a
href='function.fsockopen'>function.fsockopen</a>]:
php_network_getaddresses: getaddrinfo failed: No such host is known."

What version of the product are you using? On what operating system?
reCaptcha: 1.9
php: 5.2.3 
Windows XP 

Please provide any additional information below.

Original issue reported on code.google.com by jayanth....@gmail.com on 17 Sep 2007 at 10:08

GoogleCodeExporter commented 9 years ago
Curl is the only way to really reliably get around this... here's something I 
whipped
together...

function _recaptcha_http_post($host, $path, $data, $port = 80) {
        $req = _recaptcha_qsencode ($data);
    $ch = curl_init();  
    $pageurl = "http://".$host.$path;
        curl_setopt($ch, CURLOPT_POST, 1 );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 8000);
    curl_setopt($ch,CURLOPT_PROXY,'roxy.mpsaz.org');
    curl_setopt($ch, CURLOPT_URL, $pageurl );
    $html = curl_exec ( $ch );

       $response = preg_split("/[\s]+/", $html);

       return $response;
}

There was some really hacky logic happening with explodes everywhere, so I 
condensed
everything and changed the function "recaptcha_check_answer" as well...

function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response,
$extra_params = array())
{
    if ($privkey == null || $privkey == '') {
        die ("To use reCAPTCHA you must get an API key from <a
href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
    }

    if ($remoteip == null || $remoteip == '') {
        die ("For security reasons, you must pass the remote ip to reCAPTCHA");
    }

        //discard spam submissions
        if ($challenge == null || strlen($challenge) == 0 || $response == null ||
strlen($response) == 0) {
                $recaptcha_response = new ReCaptchaResponse();
                $recaptcha_response->is_valid = false;
                $recaptcha_response->error = 'incorrect-captcha-sol';
                return $recaptcha_response;
        }

        $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/verify",
                                          array (
                                                 'privatekey' => $privkey,
                                                 'remoteip' => $remoteip,
                                                 'challenge' => $challenge,
                                                 'response' => $response
                                                 ) + $extra_params
                                          );
        $recaptcha_response = new ReCaptchaResponse();
        if (trim ($response[0]) == 'true') {
                $recaptcha_response->is_valid = true;
        }
        else {
                $recaptcha_response->is_valid = 0;
                $recaptcha_response->error = $response[1];
        }
        return $recaptcha_response;

}

Thanks,

Richard Foreman
Mesa Public Schools
orforema@mpsaz.org

Original comment by richie.f...@gmail.com on 6 May 2008 at 7:34

Attachments: