Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added proxy configuration #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ or you can pass it in through the Form option:
echo Recaptcha::render([ 'template' => 'customCaptcha' ]);
```

### Curl (for V2 only)
To define a proxy server for Curl:

```php
'options' => [
'curl_proxy' => 'yourproxyip.com:3128', // <domain or ip>:<port number>
],

or on .env add

CURL_PROXY=yourproxyip.com:3128 #<domain or ip>:<port number>
```


### v1 customization

For the v1 customization options, consult [the old documentation](https://developers.google.com/recaptcha/old/docs/customization) and apply accordingly.
Expand Down
27 changes: 24 additions & 3 deletions src/Service/CheckRecaptchaV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ public function check($challenge, $response)
$url = 'https://www.google.com/recaptcha/api/siteverify?' . $parameters;
$checkResponse = null;

$proxy = app('config')->get('recaptcha.options.curl_proxy', '');

// prefer curl, but fall back to file_get_contents
if ('curl' === app('config')->get('recaptcha.driver') && function_exists('curl_version')) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, app('config')->get('recaptcha.options.curl_timeout', 1));
if(app('config')->get('recaptcha.options.curl_verify') === false) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

//set proxy
if ($proxy) {
curl_setopt($curl, CURLOPT_PROXY, $proxy);
}

if (app('config')->get('recaptcha.options.curl_verify') === false) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
}

$checkResponse = curl_exec($curl);
Expand All @@ -43,7 +51,20 @@ public function check($challenge, $response)
app('log')->error('[Recaptcha] CURL error: '.curl_error($curl));
}
} else {
$checkResponse = file_get_contents($url);
if($proxy) { //when has proxy
$context = array(
'http' => array(
'proxy' => $proxy,
'request_fulluri' => True,
),
);

$context = stream_context_create($context);

$checkResponse = file_get_contents($url, False, $context);
} else {
$checkResponse = file_get_contents($url);
}
}

if (is_null($checkResponse) || empty( $checkResponse )) {
Expand Down
2 changes: 1 addition & 1 deletion src/config/recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

'curl_timeout' => 1,
'curl_verify' => true,

'curl_proxy' => env('CURL_PROXY','')
],

/*
Expand Down