# final class \SmartCaptcha
{ } ::

Class: SmartCaptcha - Manages, Render and Check the Captcha Form.

- Language: PHP
- Located at: lib/core/plugins/lib_captcha_form.php
- Package: Application:Plugins:Captcha
- Namespace: \
- Class Name: SmartCaptcha
- Version: v.20241115
- Depends: constants: SMART_FRAMEWORK_SECURITY_KEY ; classes: Smart, SmartUtils, SmartTextTranslations, SmartSVGCaptcha, SmartQR2DBarcode ; javascript: jquery.js, smart-framework.pak.js
- Hints: To render captcha, SmartCaptcha::drawCaptchaForm() and a captcha plugin is required. To verify, use SmartCaptcha::verifyCaptcha() ; SmartCaptcha::clearCaptcha() is optional to be call after verify, depending how SmartCaptcha::verifyCaptcha() is called
- Usage: static object: Class::method() - This class provides only STATIC methods

## class Methods

public static function initCaptchaPlugin ( string $y_form_name, string $y_captcha_word, string $y_mode = "cookie" ) {} :: BOOL
@return: {BOOLEAN} TRUE on success or FALSE on failure
Inits a captha plugin by setting the required values in cookie or session depend how mode is set
This should be used only with external captcha Plugins (ex: external captcha image by custom URL)
This must not be used if the drawCaptchaForm() is using internal captcha mode with no external URL
public static function drawCaptchaForm ( string $y_form_name, string $y_captcha_image_url = "", string $y_mode = "cookie", bool $y_use_absolute_url = false, bool $y_include_js_requirements = false ) {} :: STRING
@return: {STRING} The partial captcha HTML to include in a form
Draw the Captcha Form partial HTML
By default if no external URL is specified will use the internal interractive captcha
IMPORTANT: When using the interractive internal captcha must not call initCaptchaPlugin() because the underlaying method initCaptcha() is automatically called !
Difficulty levels for the internal interractive captcha:
#very-easy
#easy
#moderate
#hard
#very-hard
public static function verifyCaptcha ( string $y_form_name, bool $y_clear = true, string $y_mode = "cookie" ) {} :: BOOL
@return: {BOOLEAN} TRUE on success or FALSE on failure
Verify Captcha and *OPTIONAL* Clear It
public static function clearCaptcha ( string $y_form_name, string $y_mode = "cookie", bool $y_nodelete = false ) {} :: BOOL
@return: {BOOLEAN} TRUE on success or FALSE on failure
Programatically clear the Captcha (from cookie or session)
On Verify Success the Captcha clears automatically all stored values

## class Properties

## class Constants

## Sample code: PHP

`

    <?php

    //==
     //-- captch form needs a captcha plugin to work with (ex: image)
     // See: \SmartModExtLib\Samples\TestUnitMain::captchaImg()
     // Also See: modules/mod-samples/testunit.php # case 'testunit.captcha'
     // The method SmartCaptcha::initCaptchaPlugin() must be used only to init an external captcha plugin (ex: image)
     //-- captcha form (draw)
     echo SmartCaptcha::drawCaptchaForm('form_name', '?page=samples.testunit&op=testunit.captcha'); // this controller should output HTML code to render the form
     //-- captcha check (verify)
     echo $check = SmartCaptcha::verifyCaptcha('form_name', true, 'cookie'); // and this is the way you verify the captcha (1 = ok ; 0 = not ok)
     //-- some more info on verify()
     // captcha will reset (clear) by default upon each SmartCaptcha::verifyCaptcha()
     // to avoid this (default) behaviour, you can set the 3rd parameters of verify() to FALSE
     // but if you do so, don't forget to manually clear captcha by calling SmartCaptcha::clearCaptcha() at the end !!!
     //--
     //==

    // #end php code

`

documentation generated on: 2024-12-16 16:53:46 +0000

Smart.Framework © 2009-2024 unix-world.org