简体   繁体   中英

PHP - Google Recaptcha proxy setup

I am using PHP wrapper library for Google Recaptcha.
https://packagist.org/packages/google/recaptcha

I need to set up a proxy, but as I investigate, this library does not have support for proxy configuration.

Is there anyone who has the opportunity to successfully configure a proxy configuration for Google Recaptcha?

This is properly working code on the server without proxy

    /**
     * RecaptchaService constructor.
     *
     * @param ReCaptcha $recaptcha
     */
    public function __construct(ReCaptcha $recaptcha)
    {
        $this->recaptcha = $recaptcha;
    }

    /**
     * @param array $data
     *
     * @return bool
     */
    public function validateCaptcha(array $data): bool
    {
        $response = $this->recaptcha->verify($data['gRecaptchaResponse'], $data['clientIp']);

        return $response->isSuccess() || \PHP_SAPI === 'cli';
    }

I guess that proxy should be configured before or within the verify method call.

There is a fork of Google ReCaptcha library with proxy support

https://github.com/toskadv/recaptcha

$curl = new ReCaptcha\RequestMethod\CurlPost(null, null, [
    CURLOPT_PROXY => 'http://127.0.0.1:9050/',
    CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5
]);
$recaptcha = new \ReCaptcha\ReCaptcha($secret, $curl);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
    // verified!
} else {
    $errors = $resp->getErrorCodes();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM