Class \Prado\Web\UI\WebControls\TReCaptcha
TReCaptcha displays a reCAPTCHA (a token displayed as an image) that can be used to determine if the input is entered by a real user instead of some program. It can also prevent multiple submits of the same form either by accident, or on purpose (ie. spamming).
The reCAPTCHA to solve (a string consisting of two separate words) displayed is automatically generated by the reCAPTCHA system at recaptcha.net. However, in order to use the services of the site you will need to register and get a public and a private API key pair, and supply those to the reCAPTCHA control through setting the \Prado\Web\UI\WebControls\setPrivateKey and \Prado\Web\UI\WebControls\setPublicKey properties.
Currently the reCAPTCHA API supports only one reCAPTCHA field per page, so you MUST make sure that all your input is protected and validated by a single reCAPTCHA control. Placing more than one reCAPTCHA control on the page will lead to unpredictable results, and the user will most likely unable to solve any of them successfully.
Upon postback, user input can be validated by calling validate(). The TReCaptchaValidator control can also be used to do validation, which provides server-side validation. Calling (@link validate()) will invalidate the token supplied, so all consecutive calls to the method - without solving a new captcha - will return false. Therefore if implementing a multi-stage input process, you must make sure that you call validate() only once, either at the end of the input process, or you store the result till the end of the processing.
The following template shows a typical use of TReCaptcha control:
<com:TReCaptcha ID="Captcha"
PublicKey="..."
PrivateKey="..."
/>
<com:TReCaptchaValidator ControlToValidate="Captcha"
ErrorMessage="You are challenged!" />
Class hierarchy
- \Prado\Web\UI\WebControls\TReCaptcha implements IValidatable
- \Prado\Web\UI\WebControls\TWebControl implements IStyleable
- \Prado\Web\UI\TControl implements IRenderable, IBindable
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.2
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getTagName() : string
Returns the tag name used for this control.
By default, the tag name is 'span'. You can override this method to provide customized tag names. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
renderContents(mixed $writer) : mixed
Renders the body content enclosed between the control tag.
By default, child controls and text strings will be rendered. You can override this method to provide customized content rendering. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
protected
|
addAttributesToRender(mixed $writer) : mixed
Adds attribute name-value pairs to renderer.
By default, the method will render 'id', 'accesskey', 'disabled', 'tabindex', 'title' and all custom attributes. The method can be overriden to provide customized attribute rendering. |
protected
|
|
private
|
recaptcha_check_answer(string $privkey, string $remoteip, string $challenge, string $response[, array<string|int, mixed> $extra_params = [] ]) : bool
Calls an HTTP POST function to verify if the user's guess was correct
|
private
|
recaptcha_get_html(string $pubkey[, string $error = null ][, bool $use_ssl = false ]) : string
Gets the challenge HTML (javascript and non-javascript version).
This is called from the browser, and the resulting reCAPTCHA HTML widget is embedded within the HTML form it was called from. |
private
|
recaptcha_http_post(string $host, string $path, array<string|int, mixed> $data[, int $port = 80 ]) : array<string|int, mixed>
Submits an HTTP POST to a reCAPTCHA server
|
private
|
recaptcha_qsencode(array<string|int, mixed> $data) : string
Encodes the given data into a query string format
|
public
mixed
|
ChallengeFieldName
|
'recaptcha_challenge_field'
|
public
mixed
|
RECAPTCHA_API_SECURE_SERVER
|
"https://www.google.com/recaptcha/api"
|
public
mixed
|
RECAPTCHA_API_SERVER
|
"http://www.google.com/recaptcha/api"
|
public
mixed
|
RECAPTCHA_JS
|
'http://www.google.com/recaptcha/api/js/recaptcha_ajax.js'
|
public
mixed
|
RECAPTCHA_VERIFY_SERVER
|
"www.google.com"
|
public
mixed
|
ResponseFieldName
|
'recaptcha_response_field'
|