Open GoogleCodeExporter opened 8 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:
Original issue reported on code.google.com by
jayanth....@gmail.com
on 17 Sep 2007 at 10:08