Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 1.5 KB

File metadata and controls

40 lines (33 loc) · 1.5 KB

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
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->setExpectedHostname('recaptcha-demo.appspot.com')
                  ->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
    // Verified!
} else {
    $errors = $resp->getErrorCodes();
}

The ReCaptcha class automatically chooses a method to communicate with the reCAPTCHA service based on your server's capabilities. See the Alternate request methods section in the README for more details.

Adding new request methods

Create a class that implements the RequestMethod interface. The convention is to name this class RequestMethod\MethodTypePost. Take a look at RequestMethod\CurlPost with the matching RequestMethod/CurlPostTest to see this pattern in action.

Error conventions

The client returns the response as provided by the reCAPTCHA services augmented with additional error codes based on the client's checks. When adding a new RequestMethod ensure that it returns the ReCaptcha::E_CONNECTION_FAILED and ReCaptcha::E_BAD_RESPONSE where appropriate.