PHP code example of codeit / recaptcha2
1. Go to this page and download the library: Download codeit/recaptcha2 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/ */
codeit / recaptcha2 example snippets
use ReCaptcha2\Captcha\ReCaptcha2;
use Laminas\Form\Element;
use Laminas\Form\Form;
//...
$form->add([
'name' => 'captcha',
'type' => Element\Captcha::class,
'options' => [
'captcha' => [
'class' => ReCaptcha2::class,
'options' => [
'siteKey' => '<siteKey>',
'secretKey' => '<secretKey>',
],
],
],
]);
use ReCaptcha2\Captcha\NoCaptchaService;
use ReCaptcha2\Captcha\ReCaptcha2;
use Laminas\Form\Element;
use Laminas\Form\Form;
use Laminas\Http\Client;
//...
$form->add([
'name' => 'captcha',
'type' => Element\Captcha::class,
'options' => [
'captcha' => [
'class' => ReCaptcha2::class, // Required
'options' => [
// Required:
'siteKey' => '<siteKey>',
'secretKey' => '<secretKey>',
// Optional:
'service' => [
'class' => NoCaptchaService::class, //Default = ReCaptcha2\Captcha\NoCaptchaService
'options' => [
'httpClient' => [
'class' => Client::class, //Default = Laminas\Http\Client
'options' => [
//Laminas\Http\Client configuration
],
],
],
],
],
],
],
]);
$form->add([
'name' => 'captcha',
'type' => Element\Captcha::class,
'options' => [
'captcha' => [
'class' => ReCaptcha2::class,
'options' => [
'siteKey' => '<siteKey>',
'secretKey' => '<secretKey>',
'service' => [
'options' => [
'httpClient' => [
'options' => [
'sslcafile' => ReCaptcha2\Captcha\NoCaptchaService::CACERT_PATH,
],
],
],
],
],
],
],
]);
PHP Warning: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed