Captcha PHP space does not support sockets but reCAPTCHA usage when supporting curl

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.