PHP code example of omasn / decaptcha-bundle

1. Go to this page and download the library: Download omasn/decaptcha-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

omasn / decaptcha-bundle example snippets


// in app/AppKernel.php
public function registerBundles() {
	$bundles = [
		...
		new Omasn\DecaptchaBundle\DecaptchaBundle(),
	];
	...
}

// src/AppBundle/Controller/DefaultController.php
...
public function indexAction()
{
    $oReCapcha = $this->get('decaptcha.ru_captcha');
    $iBalance = $oReCapcha->getBalance();
    ...
    if ($oReCapcha->recognize('http://site.ru/captcha.jpg')) {
        $code = $oReCapcha->getCode();
        if (!$myApp->validCode($code)) {
            $oReCapcha->notTrue(); // not valid code request in api
        }
    } else {
        $error = $oReCapcha->getError();
    }
}
...

// src/AppBundle/Controller/DefaultController.php

use Omasn\DecaptchaBundle\Services\RuCaptcha;

...
public function indexAction()
{
    $oReCapcha = $this->get('decaptcha.ru_captcha');
    $oReCapcha->setParams([
        RuCaptcha::ACTION_FIELD_FILE => '/file/to/path',
    ]);
}
...