1. Modify the two methods in the recaptchalib.php
Copy the Code code as follows:
function _recaptcha_http_post ($host, $path, $data, $port = 80) {
$req = _recaptcha_qsencode ($data);
$response = ";
$url = $host. $path;
$post _data = $req;
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
We're in post data Oh!
curl_setopt ($ch, Curlopt_post, 1);
Add the post variable to the
curl_setopt ($ch, Curlopt_postfields, $post _data);
$output = curl_exec ($ch);
Curl_close ($ch);
Echo $output;
$response = $output;
return $response;
}
function Recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra _params = Array ())
{
if ($privkey = = NULL | | $privkey = = ') {
Die ("To use ReCAPTCHA must get a API key from Https://www.google.com/recaptcha/admin/create");
}
if ($remoteip = = NULL | | $remoteip = = ') {
Die (' for security reasons, 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, "/recaptcha/api/verify",
Array (
' Privatekey ' = $privkey,
' Remoteip ' = $remoteip,
' Challenge ' = $challenge,
' Response ' = $response
) + $extra _params
);
$answers = explode ("\ n", $response [1]);
$recaptcha _response = new Recaptcharesponse ();
$pos = Strpos ($response, ' true ');
if ($pos = = = False) {
$recaptcha _response->is_valid = false;
$recaptcha _response->error = $response;
} else {
$recaptcha _response->is_valid = true;
}
return $recaptcha _response;
}
2.demo.php
Copy the Code code as follows:
The above describes the captcha PHP space does not support the socket but support curl when the use of reCAPTCHA, including the captcha aspect of the content, I hope to be interested in PHP tutorial friends helpful.