@@ -63,21 +63,58 @@ functionality into your frontend.
63
63
64
64
This library comes in when you need to verify the user's response. On the PHP
65
65
side you need the response from the reCAPTCHA service and secret key from your
66
- credentials. Instantiate the ` ReCaptcha ` class with your secret key and then
67
- pass the response to the ` verify() ` method.
66
+ credentials. Instantiate the ` ReCaptcha ` class with your secret key, specify any
67
+ additional validation rules, and then call ` verifyAndValidate() ` with the
68
+ reCAPTCHA response and user's IP address. For example:
68
69
69
70
``` php
70
71
<?php
71
72
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
72
- $resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
73
+ $resp = $recaptcha->setExpectedHostname('recaptcha-demo.appspot.com')
74
+ ->verifyAndValidate($gRecaptchaResponse, $remoteIp);
73
75
if ($resp->isSuccess()) {
74
76
// Verified!
75
77
} else {
76
78
$errors = $resp->getErrorCodes();
77
79
}
78
80
```
79
81
80
- For more usage details, see [ ARCHITECTURE] ( ARCHITECTURE.md ) .
82
+ The following methods are available:
83
+
84
+ - ` setExpectedHostname($hostname) ` : ensures the hostname matches. You must do
85
+ this if you have disabled "Domain/Package Name Validation" for your
86
+ credentials.
87
+ - ` setExpectedApkPackageName($apkPackageName) ` : if you're verifying a response
88
+ from an Android app. Again, you must do this if you have disabled
89
+ "Domain/Package Name Validation" for your credentials.
90
+ - ` setExpectedAction($action) ` : ensures the action matches for the v3 API.
91
+ - ` setScoreThreshold($threshold) ` : set a score theshold for responses from the
92
+ v3 API
93
+ - ` setChallengeTimeout($timeoutSeconds) ` : set a timeout between the user passing
94
+ the reCAPTCHA and your server processing it.
95
+
96
+ Each of the ` set ` \* ` () ` methods return the ` ReCaptcha ` instance so you can chain them
97
+ together. For example:
98
+
99
+ ``` php
100
+ <?php
101
+ $recaptcha = new \ReCaptcha\ReCaptcha($secret);
102
+ $resp = $recaptcha->setExpectedHostname('recaptcha-demo.appspot.com')
103
+ ->setExpectedAction('homepage')
104
+ ->setScoreThreshold(0.5)
105
+ ->verifyAndValidate($gRecaptchaResponse, $remoteIp);
106
+
107
+ if ($resp->isSuccess()) {
108
+ // Verified!
109
+ } else {
110
+ $errors = $resp->getErrorCodes();
111
+ }
112
+ ```
113
+
114
+ You can find the constants for the libraries error codes in the ` ReCaptcha `
115
+ class constants, e.g. ` ReCaptcha::E_HOSTNAME_MISMATCH `
116
+
117
+ For more details on usage and structure, see [ ARCHITECTURE] ( ARCHITECTURE.md ) .
81
118
82
119
### Examples
83
120
0 commit comments