Documentation

ReCaptcha
in package

reCAPTCHA client.

Table of Contents

Constants

E_ACTION_MISMATCH  = 'action-mismatch'
Expected action did not match
E_APK_PACKAGE_NAME_MISMATCH  = 'apk_package_name-mismatch'
Expected APK package name did not match
E_BAD_RESPONSE  = 'bad-response'
Did not receive a 200 from the service
E_CHALLENGE_TIMEOUT  = 'challenge-timeout'
Challenge timeout
E_CONNECTION_FAILED  = 'connection-failed'
Could not connect to service
E_HOSTNAME_MISMATCH  = 'hostname-mismatch'
Expected hostname did not match
E_INVALID_JSON  = 'invalid-json'
Invalid JSON received
E_MISSING_INPUT_RESPONSE  = 'missing-input-response'
ReCAPTCHA response not provided
E_SCORE_THRESHOLD_NOT_MET  = 'score-threshold-not-met'
Score threshold not met
E_UNKNOWN_ERROR  = 'unknown-error'
Not a success, but no error codes received!
SITE_VERIFY_URL  = 'https://www.google.com/recaptcha/api/siteverify'
URL for reCAPTCHA siteverify API
VERSION  = 'php_1.2.4'
Version of this client library.

Properties

$requestMethod  : RequestMethod
Method used to communicate with service. Defaults to POST request.
$secret  : string
Shared secret for the site.

Methods

__construct()  : mixed
Create a configured instance to use the reCAPTCHA service.
setChallengeTimeout()  : ReCaptcha
Provide a timeout in seconds to test against the challenge timestamp in verify()
setExpectedAction()  : ReCaptcha
Provide an action to match against in verify() This should be set per page.
setExpectedApkPackageName()  : ReCaptcha
Provide an APK package name to match against in verify()
setExpectedHostname()  : ReCaptcha
Provide a hostname to match against in verify() This should be without a protocol or trailing slash, e.g. www.google.com
setScoreThreshold()  : ReCaptcha
Provide a threshold to meet or exceed in verify() Threshold should be a float between 0 and 1 which will be tested as response >= threshold.
verify()  : Response
Calls the reCAPTCHA siteverify API to verify whether the user passes CAPTCHA test and additionally runs any specified additional checks

Constants

E_ACTION_MISMATCH

Expected action did not match

public mixed E_ACTION_MISMATCH = 'action-mismatch'
Tags
const

string

E_APK_PACKAGE_NAME_MISMATCH

Expected APK package name did not match

public mixed E_APK_PACKAGE_NAME_MISMATCH = 'apk_package_name-mismatch'
Tags
const

string

E_BAD_RESPONSE

Did not receive a 200 from the service

public mixed E_BAD_RESPONSE = 'bad-response'
Tags
const

string

E_CHALLENGE_TIMEOUT

Challenge timeout

public mixed E_CHALLENGE_TIMEOUT = 'challenge-timeout'
Tags
const

string

E_CONNECTION_FAILED

Could not connect to service

public mixed E_CONNECTION_FAILED = 'connection-failed'
Tags
const

string

E_HOSTNAME_MISMATCH

Expected hostname did not match

public mixed E_HOSTNAME_MISMATCH = 'hostname-mismatch'
Tags
const

string

E_INVALID_JSON

Invalid JSON received

public mixed E_INVALID_JSON = 'invalid-json'
Tags
const

string

E_MISSING_INPUT_RESPONSE

ReCAPTCHA response not provided

public mixed E_MISSING_INPUT_RESPONSE = 'missing-input-response'
Tags
const

string

E_SCORE_THRESHOLD_NOT_MET

Score threshold not met

public mixed E_SCORE_THRESHOLD_NOT_MET = 'score-threshold-not-met'
Tags
const

string

E_UNKNOWN_ERROR

Not a success, but no error codes received!

public mixed E_UNKNOWN_ERROR = 'unknown-error'
Tags
const

string

SITE_VERIFY_URL

URL for reCAPTCHA siteverify API

public mixed SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'
Tags
const

string

VERSION

Version of this client library.

public mixed VERSION = 'php_1.2.4'
Tags
const

string

Properties

$requestMethod

Method used to communicate with service. Defaults to POST request.

private RequestMethod $requestMethod

$secret

Shared secret for the site.

private string $secret

Methods

__construct()

Create a configured instance to use the reCAPTCHA service.

public __construct(string $secret[, RequestMethod $requestMethod = null ]) : mixed
Parameters
$secret : string

The shared key between your site and reCAPTCHA.

$requestMethod : RequestMethod = null

method used to send the request. Defaults to POST.

Tags
throws
RuntimeException

if $secret is invalid

setChallengeTimeout()

Provide a timeout in seconds to test against the challenge timestamp in verify()

public setChallengeTimeout(int $timeoutSeconds) : ReCaptcha
Parameters
$timeoutSeconds : int

Expected hostname

Return values
ReCaptcha

Current instance for fluent interface

setExpectedAction()

Provide an action to match against in verify() This should be set per page.

public setExpectedAction(string $action) : ReCaptcha
Parameters
$action : string

Expected action

Return values
ReCaptcha

Current instance for fluent interface

setExpectedApkPackageName()

Provide an APK package name to match against in verify()

public setExpectedApkPackageName(string $apkPackageName) : ReCaptcha
Parameters
$apkPackageName : string

Expected APK package name

Return values
ReCaptcha

Current instance for fluent interface

setExpectedHostname()

Provide a hostname to match against in verify() This should be without a protocol or trailing slash, e.g. www.google.com

public setExpectedHostname(string $hostname) : ReCaptcha
Parameters
$hostname : string

Expected hostname

Return values
ReCaptcha

Current instance for fluent interface

setScoreThreshold()

Provide a threshold to meet or exceed in verify() Threshold should be a float between 0 and 1 which will be tested as response >= threshold.

public setScoreThreshold(float $threshold) : ReCaptcha
Parameters
$threshold : float

Expected threshold

Return values
ReCaptcha

Current instance for fluent interface

verify()

Calls the reCAPTCHA siteverify API to verify whether the user passes CAPTCHA test and additionally runs any specified additional checks

public verify(string $response[, string $remoteIp = null ]) : Response
Parameters
$response : string

The user response token provided by reCAPTCHA, verifying the user on your site.

$remoteIp : string = null

The end user's IP address.

Return values
Response

Response from the service.


        
On this page

Search results