Constants

RECAPTCHA_API_SERVER

RECAPTCHA_API_SERVER

RECAPTCHA_VERIFY_SERVER

RECAPTCHA_VERIFY_SERVER

RECAPTCHA_HEADER

RECAPTCHA_HEADER

Properties

$Version

$Version : string

reCAPTCHA Library Version

Type

string

$timeout

$timeout : integer

Server response timeout

Type

integer

$_recaptchaOptions

$_recaptchaOptions : array

reCAPTCHA Theme default options RecaptchaOptions Reference: {@link: https://developers.google.com/recaptcha/docs/customization}

Type

array

$_standardThemes

$_standardThemes : array

List of Standard Theme names available Standard names Reference: {@link: https://developers.google.com/recaptcha/docs/customization#Standard_Themes}

Type

array

$_optionsWrapper

$_optionsWrapper : string

Theme JavaScript wrapper

Type

string

$_builtInlang

$_builtInlang : array

For comparison of built in i18n languages

Type

array

$_publicKey

$_publicKey : string

Public API KEY

Type

string

$_privateKey

$_privateKey : string

Private API KEY

Type

string

$_ssl

$_ssl : bool

Enable / Disable API call via SSL

Type

bool

$_remoteIP

$_remoteIP : string

Remote IP

Type

string

$_error

$_error : string

Error message response

Type

string

Methods

custom_theme()

custom_theme(string $widget_id) : string

Custom Theme Template In order to use a custom theme, you must set reCAPTCHA options correctly, also provide a custom CSS to display it properly.

Fully custom theme reference: {@link: https://developers.google.com/recaptcha/docs/customization#Custom_Theming}

Parameters

string $widget_id

The ID name for wrapper container

Returns

string

setTranslation()

setTranslation(string $language, string $path) : void

Custom Translations

In order to use custom translation (even if it is not built in specially for a custom theme), the translations must be set manually by this method or by passing the lang two letters code to instance constructor. It will set translation by a lang code given and overwrites other languages set in an external captcha_config file.

NOTE: If translate file recaptcha.lang[lang_code].php with its respective translation strings within a folder i18n is not found a default lang English 'en' will be used instead.

To use an external file for a custom lang translation you must create a copy of some lang file already done within the folder I18n and rename it as 'recaptcha.lang[lang_code].php' place it wherever you want and tell as second parameter its absolute $path without filename

Parameters

string $language

Two letter language code e.g: (Italian = 'it')

string $path

Optional path to translate file

clientLang()

clientLang() : string

Get user's browser language preference

Returns

string

__construct()

__construct(string $lang, bool $https) : void

Instance constructor

Parameters

string $lang

Changes the widget language

bool $https

Enable using reCAPTCHA in SSL sites

setConfig()

setConfig(string $config_location) : void

Set global reCAPTCHA options by loading an external config file these options can be set for all instances of reCAPTCHA in your app, this avoid to set options, private and public Keys all the time individualy within your forms that has a Captcha widget.

Parameters

string $config_location

The absolute path to config file

Throws

\ReCaptcha\CaptchaException

setPublicKey()

setPublicKey(string $key) : void

Set Public API KEY

Parameters

string $key

setPrivateKey()

setPrivateKey(string $key) : void

Set Private API KEY

Parameters

string $key

setRemoteIp()

setRemoteIp(string $ip_address) : void

Set a remote client IP Optional setter for an alternative IP address whether REMOTE_ADDR is empty, anyway default value for FALLBACK is 127.0.0.1 Use this setter to use a different one.

Parameters

string $ip_address

The valid IP address

setError()

setError(string $e) : void

Set reCAPTCHA server Response error.

NOTE: Default string error is: incorrect-captcha-sol Use this function to overwrite with your own message.

Parameters

string $e

The error message string. Optional Whether this parameter is NULL, it will retrieve

   an error message translated by a given lang e.g: 'it' (for Italian) returns 'Scorretto. Riprova.'

getError()

getError() : void

Get reCAPTCHA server Response error

displayHTML()

displayHTML(string $theme_name, array $options) : string

Create embedded widget script HTML called within a form

NOTE: $theme_name is used to set theme name separated instead set it within array of options available, this is to keep compatibility for newer version in future.

Parameters

string $theme_name

Optional Standard_Theme or custom theme name

array $options

Optional array of reCAPTCHA options

Throws

\ReCaptcha\CaptchaException

Returns

string —

The reCAPTCHA widget embed HTML

isValid()

isValid() : bool

Verifying reCAPTCHA User's Answer resolves response challenge return TRUE if the answer matches

Returns

bool

_theme()

_theme(string $theme_name, array $options) : string

Standard Theme Display's Theme customization for reCAPTCHA widget by writting a snippet for Standard_Themes and Custom_Theming

Parameters

string $theme_name

Optional theme name. NOTE: overwrite theme if it's set in an external config

array $options

reCAPTCHA Associative array of available options. NOTE: overwrite options set in an external config

Returns

string —

Standard_Theme | Custom_Theme | Fallback default reCAPTCHA theme

i18n()

i18n(string $key, string $path) : array|string

Fetch I18n language line

Parameters

string $key

The string translated

string $path

Optional path to your own language file

Returns

array|string

_postHttpChallenge()

_postHttpChallenge(array $data) : array

reCAPTCHA API Request

Post reCAPTCHA input challenge, response Uses function fsockopen() and curl() as a fallback If both functions are unavailable in server configuration an {@link \ReCaptcha\CaptchaException} exception will be thrown

Parameters

array $data

Array of reCAPTCHA parameters

Throws

\ReCaptcha\CaptchaException

Returns

array

_remoteIp()

_remoteIp() : string

Get the client remote IP in order to send post to the API must have an IP set for sometimes IP is empty, so we set a FALLBACK for that.

Returns

string

_sanitizeField()

_sanitizeField(string $recaptcha_input_field) : string

Sanitizes recaptcha_input_field

Parameters

string $recaptcha_input_field

The input string to be sanitized

Returns

string

_buildServerURI()

_buildServerURI(string $path) : string

Build API server URI

Parameters

string $path

The path whether is noscript for iframe or not

Returns

string