Пример #1
0
    $req = _recaptcha_qsencode($data);
    $http_request = "POST {$path} HTTP/1.0\r\n";
    $http_request .= "Host: {$host}\r\n";
    $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
    $http_request .= "Content-Length: " . strlen($req) . "\r\n";
    $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
    $http_request .= "\r\n";
    $http_request .= $req;
    $response = '';
    if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10))) {
        die('Could not open socket');
    }
    fwrite($fs, $http_request);
    while (!feof($fs)) {
        $response .= fgets($fs, 1160);
    }
    // One TCP-IP packet
    fclose($fs);
    $response = explode("\r\n\r\n", $response, 2);
    return $response;
}
/**
 * Gets the challenge HTML (javascript and non-javascript version).
 * This is called from the browser, and the resulting reCAPTCHA HTML widget
 * is embedded within the HTML form it was called from.
 * @param string $pubkey A public key for reCAPTCHA
 * @param string $error The error given by reCAPTCHA (optional, default is null)
Пример #2
0
/**
 * Calls an HTTP POST function to verify if the user's guess was correct
 * @param string $privkey
 * @param string $remoteip
 * @param string $challenge
 * @param string $response
 * @param array $extra_params an array of extra variables to post to the server
 * @return ReCaptchaResponse
 */
function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array())
{
    if ($privkey == null || $privkey == '') {
        trigger_error("reCAPTCHA - No private key", E_USER_NOTICE);
        return false;
    }
    if ($remoteip == null || $remoteip == '') {
        trigger_error("reCAPTCHA - No remote ip", E_USER_NOTICE);
        return false;
    }
    //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);
    $answers = explode("\n", $response[1]);
    $recaptcha_response = new ReCaptchaResponse();
    if (trim($answers[0]) == 'true') {
        $recaptcha_response->is_valid = true;
    } else {
        $recaptcha_response->is_valid = false;
        $recaptcha_response->error = $answers[1];
    }
    return $recaptcha_response;
}
Пример #3
0
<?php
Пример #4
0
/**
 * Calls an HTTP POST function to verify if the user's guess was correct
 * @param string $privkey
 * @param string $remoteip
 * @param string $challenge
 * @param string $response
 * @param array $extra_params an array of extra variables to post to the server
 * @return ReCaptchaResponse
 */
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>", "wp-recaptcha"));
    }
    if ($remoteip == null || $remoteip == '') {
        die(__("For security reasons, you must pass the remote ip to reCAPTCHA", "wp-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(gethostbyname('api-verify.recaptcha.net'), "/verify", array('privatekey' => $privkey, 'remoteip' => $remoteip, 'challenge' => $challenge, 'response' => $response) + $extra_params);
    $answers = explode("\n", $response[1]);
    $recaptcha_response = new ReCaptchaResponse();
    if (trim($answers[0]) == 'true') {
        $recaptcha_response->is_valid = true;
    } else {
        $recaptcha_response->is_valid = false;
        $recaptcha_response->error = $answers[1];
    }
    return $recaptcha_response;
}
Пример #5
0
/**
 * Calls an HTTP POST function to verify if the user"s guess was correct
 * @param string $privkey
 * @param string $remoteip
 * @param string $challenge
 * @param string $response
 * @param array $extra_params an array of extra variables to post to the server
 * @return ReCaptchaResponse
 */
function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array())
{
    if ($privkey == null || $privkey == "") {
        return "Required reCAPTCHA Keys missing from Setup > General Settings > Security";
    }
    if ($remoteip == null || $remoteip == "") {
        return "For security reasons, you must pass the remote ip to reCAPTCHA";
    }
    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();
    if (trim($answers[0]) == "true") {
        $recaptcha_response->is_valid = true;
    } else {
        $recaptcha_response->is_valid = false;
        $recaptcha_response->error = $answers[1];
    }
    return $recaptcha_response;
}