pax_global_header 0000666 0000000 0000000 00000000064 13525550111 0014510 g ustar 00root root 0000000 0000000 52 comment=98c4a6573b27e8b0990ea8789c74ea378795134c
recaptcha-1.2.3/ 0000775 0000000 0000000 00000000000 13525550111 0013445 5 ustar 00root root 0000000 0000000 recaptcha-1.2.3/.github/ 0000775 0000000 0000000 00000000000 13525550111 0015005 5 ustar 00root root 0000000 0000000 recaptcha-1.2.3/.github/ISSUE_TEMPLATE/ 0000775 0000000 0000000 00000000000 13525550111 0017170 5 ustar 00root root 0000000 0000000 recaptcha-1.2.3/.github/ISSUE_TEMPLATE/bug_report.md 0000664 0000000 0000000 00000001520 13525550111 0021660 0 ustar 00root root 0000000 0000000 ---
name: PHP client issue
about: Report an issue with the PHP client library
---
**Issue description**
**Environment**
* OS name and version:
* PHP version:
* Web server name and version:
* `google/recaptcha` version:
* Browser name and version:
**Reproducing the issue**
* URL (optional):
* Code (optional):
***User steps***
1. Visit page...
recaptcha-1.2.3/.gitignore 0000664 0000000 0000000 00000000156 13525550111 0015437 0 ustar 00root root 0000000 0000000 /.php_cs.cache
/.phpunit.result.cache
/build
/composer.lock
/examples/config.php
/nbproject/private/
/vendor/
recaptcha-1.2.3/.travis.yml 0000664 0000000 0000000 00000001171 13525550111 0015556 0 ustar 00root root 0000000 0000000 dist: trusty
language: php
sudo: false
php:
- '5.5'
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- '7.3'
before_script:
- composer install
- phpenv version-name | grep ^5.[34] && echo "extension=apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
- phpenv version-name | grep ^5.[34] && echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
script:
- mkdir -p build/logs
- composer run-script lint
- composer run-script test
after_success:
- travis_retry php vendor/bin/php-coveralls
cache:
directories:
- "$HOME/.composer/cache/files"
git:
depth: 5
recaptcha-1.2.3/ARCHITECTURE.md 0000664 0000000 0000000 00000004745 13525550111 0015663 0 ustar 00root root 0000000 0000000 # Architecture
The general pattern of usage is to instantiate the `ReCaptcha` class with your
secret key, specify any additional validation rules, and then call `verify()`
with the reCAPTCHA response and user's IP address. For example:
```php
setExpectedHostname('recaptcha-demo.appspot.com')
->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
// Verified!
} else {
$errors = $resp->getErrorCodes();
}
```
By default, this will use the
[`stream_context_create()`](https://secure.php.net/stream_context_create) and
[`file_get_contents()`](https://secure.php.net/file_get_contents) to make a POST
request to the reCAPTCHA service. This is handled by the
[`RequestMethod\Post`](./src/ReCaptcha/RequestMethod/Post.php) class.
## Alternate request methods
You may need to use other methods for making requests in your environment. The
[`ReCaptcha`](./src/ReCaptcha/ReCaptcha.php) class allows an optional
[`RequestMethod`](./src/ReCaptcha/RequestMethod.php) instance to configure this.
For example, if you want to use [cURL](https://secure.php.net/curl) instead you
can do this:
```php
setExpectedHostname('recaptcha-demo.appspot.com')
->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
// Verified!
} else {
$errors = $resp->getErrorCodes();
}
```
The following methods are available:
- `setExpectedHostname($hostname)`: ensures the hostname matches. You must do
this if you have disabled "Domain/Package Name Validation" for your
credentials.
- `setExpectedApkPackageName($apkPackageName)`: if you're verifying a response
from an Android app. Again, you must do this if you have disabled
"Domain/Package Name Validation" for your credentials.
- `setExpectedAction($action)`: ensures the action matches for the v3 API.
- `setScoreThreshold($threshold)`: set a score theshold for responses from the
v3 API
- `setChallengeTimeout($timeoutSeconds)`: set a timeout between the user passing
the reCAPTCHA and your server processing it.
Each of the `set`\*`()` methods return the `ReCaptcha` instance so you can chain
them together. For example:
```php
setExpectedHostname('recaptcha-demo.appspot.com')
->setExpectedAction('homepage')
->setScoreThreshold(0.5)
->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
// Verified!
} else {
$errors = $resp->getErrorCodes();
}
```
You can find the constants for the libraries error codes in the `ReCaptcha`
class constants, e.g. `ReCaptcha::E_HOSTNAME_MISMATCH`
For more details on usage and structure, see [ARCHITECTURE](ARCHITECTURE.md).
### Examples
You can see examples of each reCAPTCHA type in [examples/](examples/). You can
run the examples locally by using the Composer script:
```sh
composer run-script serve-examples
```
This makes use of the in-built PHP dev server to host the examples at
http://localhost:8080/
These are also hosted on Google AppEngine Flexible environment at
https://recaptcha-demo.appspot.com/. This is configured by
[`app.yaml`](./app.yaml) which you can also use to [deploy to your own AppEngine
project](https://cloud.google.com/appengine/docs/flexible/php/download).
## Contributing
No one ever has enough engineers, so we're very happy to accept contributions
via Pull Requests. For details, see [CONTRIBUTING](CONTRIBUTING.md)
recaptcha-1.2.3/app.yaml 0000664 0000000 0000000 00000000127 13525550111 0015111 0 ustar 00root root 0000000 0000000 runtime: php
env: flex
skip_files:
- tests
runtime_config:
document_root: examples
recaptcha-1.2.3/composer.json 0000664 0000000 0000000 00000002327 13525550111 0016173 0 ustar 00root root 0000000 0000000 {
"name": "google/recaptcha",
"description": "Client library for reCAPTCHA, a free service that protects websites from spam and abuse.",
"type": "library",
"keywords": ["recaptcha", "captcha", "spam", "abuse"],
"homepage": "https://www.google.com/recaptcha/",
"license": "BSD-3-Clause",
"support": {
"forum": "https://groups.google.com/forum/#!forum/recaptcha",
"source": "https://github.com/google/recaptcha"
},
"require": {
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36|^5.7.27|^6.59|^7.5.11",
"friendsofphp/php-cs-fixer": "^2.2.20|^2.15",
"php-coveralls/php-coveralls": "^2.1"
},
"autoload": {
"psr-4": {
"ReCaptcha\\": "src/ReCaptcha"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"scripts": {
"lint": "vendor/bin/php-cs-fixer -vvv fix --using-cache=no --dry-run .",
"lint-fix": "vendor/bin/php-cs-fixer -vvv fix --using-cache=no .",
"test": "vendor/bin/phpunit --colors=always",
"serve-examples": "@php -S localhost:8080 -t examples"
},
"config": {
"process-timeout": 0
}
}
recaptcha-1.2.3/examples/ 0000775 0000000 0000000 00000000000 13525550111 0015263 5 ustar 00root root 0000000 0000000 recaptcha-1.2.3/examples/appengine-https.php 0000664 0000000 0000000 00000004027 13525550111 0021105 0 ustar 00root root 0000000 0000000 [
'site' => '',
'secret' => '',
],
'v2-invisible' => [
'site' => '',
'secret' => '',
],
'v3' => [
'site' => '',
'secret' => '',
],
];
recaptcha-1.2.3/examples/examples.css 0000664 0000000 0000000 00000000623 13525550111 0017614 0 ustar 00root root 0000000 0000000 body {
font-family: sans-serif;
margin: 0;
padding: 0;
}
h1,
h2,
p {
margin: 0;
padding: 0.5rem 0 0 0;
font-weight: normal;
}
h1,
h2 {
color: #222244;
}
header {
padding: 0.5rem 2rem 0.5rem 2rem;
background: #f0f0f4;
border-bottom: 1px solid #aaaabb;
}
main {
padding: 0.5rem 2rem 0.5rem 2rem;
}
.form-field {
display: block;
margin: 1rem;
}
.hidden {
display: none;
}
recaptcha-1.2.3/examples/google0afd8760fd68f119.html 0000664 0000000 0000000 00000000065 13525550111 0021577 0 ustar 00root root 0000000 0000000 google-site-verification: google0afd8760fd68f119.html recaptcha-1.2.3/examples/index.php 0000664 0000000 0000000 00000007332 13525550111 0017110 0 ustar 00root root 0000000 0000000
If you do not have keys already then visit https://www.google.com/recaptcha/admin to generate them. Edit this file and set the respective keys in $siteKey and $secret. Reload the page after this.
This example is sending the Content-Security-Policy header. Look at the source and inspect the network tab for this request to see what's happening. The reCAPTCHA v3 API is being called here, however you can use the same approach for the v2 API calls as well.
NOTE:This is a sample implementation, the score returned here is not a reflection on your Google account or type of traffic. In production, refer to the distribution of scores shown in your admin interface and adjust your own threshold accordingly. Do not raise issues regarding the score you see here.
reCAPTCHA script loading
grecaptcha.ready() fired, calling
grecaptcha.execute('', {action: ''})'
Received token from reCAPTCHA service, sending to our backend with:
If you do not have keys already then visit https://www.google.com/recaptcha/admin to generate them. Edit this file and set the respective keys in the config.php file or directly to $siteKey and $secret. Reload the page after this.
POST data
setExpectedHostname($_SERVER['SERVER_NAME'])
->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()):
// If the response is a success, that's it!
?>
Success!
That's it. Everything is working. Go integrate this into your real project.
If you do not have keys already then visit https://www.google.com/recaptcha/admin to generate them. Edit this file and set the respective keys in the config.php file or directly to $siteKey and $secret. Reload the page after this.
POST data
setExpectedHostname($_SERVER['SERVER_NAME'])
->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()):
// If the response is a success, that's it!
?>
Success!
That's it. Everything is working. Go integrate this into your real project.
If you do not have keys already then visit https://www.google.com/recaptcha/admin to generate them. Edit this file and set the respective keys in $siteKey and $secret. Reload the page after this.
POST data
setExpectedHostname($_SERVER['SERVER_NAME'])
->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()):
// If the response is a success, that's it!
?>
Success!
That's it. Everything is working. Go integrate this into your real project.
If you do not have keys already then visit https://www.google.com/recaptcha/admin to generate them. Edit this file and set the respective keys in $siteKey and $secret. Reload the page after this.
The reCAPTCHA v3 API provides a confidence score for each request.
NOTE:This is a sample implementation, the score returned here is not a reflection on your Google account or type of traffic. In production, refer to the distribution of scores shown in your admin interface and adjust your own threshold accordingly. Do not raise issues regarding the score you see here.
reCAPTCHA script loading
grecaptcha.ready() fired, calling
grecaptcha.execute('', {action: ''})'
Received token from reCAPTCHA service, sending to our backend with: