Recaptcha2
extends CaptchaBase
in package
Recaptcha2 class
Tags
Table of Contents
Properties
- $_activeProvider : string
- $_name : string
- $_privateKey : string|null
- $_providers : array<string|int, mixed>
- $_publicKey : string|null
Methods
- __construct() : mixed
- addProvider() : void
- Register a provider.
- getActiveProvider() : CaptchaBase
- Return active provider.
- getAllProviders() : array<string|int, CaptchaBase>
- Return all providers.
- getHtml() : string|null
- Get form input HTML to display.
- getJavascriptSource() : string
- Get JavaScript source URL.
- getJavascriptSubmit() : string|null
- Get JavaScript on submit function.
- getName() : string
- Get provider name.
- getPrivateKey() : string
- Get private key.
- getPublicKey() : string
- Get public key.
- isCaptchaEnabled() : bool
- Is captcha enabled for a given key?
- setActiveProvider() : void
- Set active provider.
- validateKey() : bool
- Validate if the public key is valid or not.
- validateSecret() : bool
- Validate if the private key is valid.
- validateToken() : bool
- Validate a Captcha token.
Properties
$_activeProvider
protected
static string
$_activeProvider
= ''
The name of the active captcha provider.
$_name
protected
string
$_name
Name of this captcha provider.
$_privateKey
protected
string|null
$_privateKey
This captcha providers private key.
$_providers
protected
static array<string|int, mixed>
$_providers
= []
All registered captcha providers.
$_publicKey
protected
string|null
$_publicKey
This captcha providers public key.
Methods
__construct()
public
__construct(string|null $privateKey, string|null $publicKey) : mixed
Parameters
- $privateKey : string|null
- $publicKey : string|null
addProvider()
Register a provider.
public
static addProvider(CaptchaBase $provider) : void
Parameters
- $provider : CaptchaBase
-
Provider instance to register
getActiveProvider()
Return active provider.
public
static getActiveProvider() : CaptchaBase
Return values
CaptchaBase —Active provider
getAllProviders()
Return all providers.
public
static getAllProviders() : array<string|int, CaptchaBase>
Return values
array<string|int, CaptchaBase> —All providers
getHtml()
Get form input HTML to display.
public
getHtml() : string|null
Return values
string|null —HTML to display
getJavascriptSource()
Get JavaScript source URL.
public
getJavascriptSource() : string
Return values
string —JS source URL
getJavascriptSubmit()
Get JavaScript on submit function.
public
getJavascriptSubmit(string $id) : string|null
Parameters
- $id : string
-
ID attribute of form
Return values
string|null —JS for submit function
getName()
Get provider name.
public
getName() : string
Return values
string —Provider name
getPrivateKey()
Get private key.
public
getPrivateKey() : string
Return values
string —Private key
getPublicKey()
Get public key.
public
getPublicKey() : string
Return values
string —Public key
isCaptchaEnabled()
Is captcha enabled for a given key?
public
static isCaptchaEnabled([string $key = 'recaptcha' ]) : bool
Parameters
- $key : string = 'recaptcha'
-
Key to lookup in db, defaults to simply recaptcha (for register, contact pages etc)
Return values
bool —Whether captcha is enabled or not
setActiveProvider()
Set active provider.
public
static setActiveProvider(string $provider) : void
Parameters
- $provider : string
-
Provider name to set as active
validateKey()
Validate if the public key is valid or not.
public
validateKey(string $key) : bool
Parameters
- $key : string
-
The public key to validate
Return values
bool —Whether the public key is valid or not
validateSecret()
Validate if the private key is valid.
public
validateSecret(string $secret) : bool
Parameters
- $secret : string
-
The secret key to validate
Return values
bool —Whether the private key is valid or not
validateToken()
Validate a Captcha token.
public
validateToken(array<string|int, mixed> $post) : bool
Parameters
- $post : array<string|int, mixed>
-
Post body to validate
Return values
bool —Whether the token was valid or not