Projet

Général

Profil

Paste
Télécharger (4,07 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / recaptcha / recaptcha-php / README.md @ 6ae446a4

1
# reCAPTCHA PHP client library
2

    
3
[![Build Status](https://travis-ci.org/google/recaptcha.svg)](https://travis-ci.org/google/recaptcha)
4
[![Latest Stable Version](https://poser.pugx.org/google/recaptcha/v/stable.svg)](https://packagist.org/packages/google/recaptcha)
5
[![Total Downloads](https://poser.pugx.org/google/recaptcha/downloads.svg)](https://packagist.org/packages/google/recaptcha)
6

    
7
* Project page: http://www.google.com/recaptcha/
8
* Repository: https://github.com/google/recaptcha
9
* Version: 1.1.2
10
* License: BSD, see [LICENSE](LICENSE)
11

    
12
## Description
13

    
14
reCAPTCHA is a free CAPTCHA service that protect websites from spam and abuse.
15
This is Google authored code that provides plugins for third-party integration
16
with reCAPTCHA.
17

    
18
## Installation
19

    
20
### Composer (Recommended)
21

    
22
[Composer](https://getcomposer.org/) is a widely used dependency manager for PHP
23
packages. This reCAPTCHA client is available on Packagist as
24
[`google/recaptcha`](https://packagist.org/packages/google/recaptcha) and can be
25
installed either by running the `composer require` command or adding the library
26
to your `composer.json`. To enable Composer for you project, refer to the
27
project's [Getting Started](https://getcomposer.org/doc/00-intro.md)
28
documentation.
29

    
30
To add this dependency using the command, run the following from within your
31
project directory:
32
```
33
composer require google/recaptcha "~1.1"
34
```
35

    
36
Alternatively, add the dependency directly to your `composer.json` file:
37
```json
38
"require": {
39
    "google/recaptcha": "~1.1"
40
}
41
```
42

    
43
### Direct download (no Composer)
44

    
45
If you wish to install the library manually (i.e. without Composer), then you
46
can use the links on the main project page to either clone the repo or download
47
the [ZIP file](https://github.com/google/recaptcha/archive/master.zip). For
48
convenience, an autoloader script is provided in `src/autoload.php` which you
49
can require into your script instead of Composer's `vendor/autoload.php`. For
50
example:
51

    
52
```php
53
require('/path/to/recaptcha/src/autoload.php');
54
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
55
```
56

    
57
The classes in the project are structured according to the
58
[PSR-4](http://www.php-fig.org/psr/psr-4/) standard, so you may of course also
59
use your own autoloader or require the needed files directly in your code.
60

    
61
### Development install
62

    
63
If you would like to contribute to this project or run the unit tests on within
64
your own environment you will need to install the development dependencies, in
65
this case that means [PHPUnit](https://phpunit.de/). If you clone the repo and
66
run `composer install` from within the repo, this will also grab PHPUnit and all
67
its dependencies for you. If you only need the autoloader installed, then you
68
can always specify to Composer not to run in development mode, e.g. `composer
69
install --no-dev`.
70

    
71
*Note:* These dependencies are only required for development, there's no
72
requirement for them to be included in your production code.
73

    
74
## Usage
75

    
76
First, register keys for your site at https://www.google.com/recaptcha/admin
77

    
78
When your app receives a form submission containing the `g-recaptcha-response`
79
field, you can verify it using:
80
```php
81
<?php
82
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
83
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
84
if ($resp->isSuccess()) {
85
    // verified!
86
} else {
87
    $errors = $resp->getErrorCodes();
88
}
89
```
90

    
91
You can see an end-to-end working example in
92
[examples/example-captcha.php](examples/example-captcha.php)
93

    
94
## Upgrading
95

    
96
### From 1.0.0
97

    
98
The previous version of this client is still available on the `1.0.0` tag [in
99
this repo](https://github.com/google/recaptcha/tree/1.0.0) but it is purely for
100
reference and will not receive any updates.
101

    
102
The major changes in 1.1.0 are:
103
* installation now via Composer;
104
* class loading also via Composer;
105
* classes now namespaced;
106
* old method call was `$rc->verifyResponse($remoteIp, $response)`, new call is
107
  `$rc->verify($response, $remoteIp)`
108

    
109
## Contributing
110

    
111
We accept contributions via GitHub Pull Requests, but all contributors need to
112
be covered by the standard Google Contributor License Agreement. You can find
113
instructions for this in [CONTRIBUTING](CONTRIBUTING.md)