Welcome Guest, Not a member yet? Register   Sign In
Alternative reCAPTCHA library
#1

Hello everbody, I create a alternative reCAPTCHA library to CodeIgniter v3.x, if you want see in the GitHub https://github.com/parg-programador/Code...aptcha.php, it's simple, but to me works.

To use it you must download the Google_recaptcha.php file and paste into application\libraries.

in Controller

I do not recommend that you configure the library to load automatically in autoload.php but you to load only the controller you will use it.

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Login extends CI_Controller {

 
   public function index() {
 
       // carrega os recursos necessários
 
       $this->load->library('google_recaptcha');

 
       // configura o Google reCAPTCHA
 
       $this->google_recaptcha->setSiteKey("**************************");
 
       $this->google_recaptcha->setSecretKey("**************************");

 
       // verifica o Google reCAPTCHA
 
       if ($this->input->post('g-recaptcha-response') != false) {
 
           $this->google_recaptcha->setResponse($this->input->post('g-recaptcha-response'));

 
           if ($this->google_recaptcha->validateResponse()) {
 
               // está válido
 
           } else {
 
               // inválido
 
           }
 
       }

 
       $this->load->view('template_login');
 
   }



in View

In its Viewer you have to enter only the Google JavaScript using getJavaScript() method in the header.

PHP Code:
<head>
 
   <title>Página de Login</title>
 
   ...
 
   <!-- reCaptcha -->
 
   <?= $this->google_recaptcha->getJavaScript() ?>
</head> 


And where you want the widget to appear reCAPTCHA use the getWidget() method.

PHP Code:
<div class="col-md-3 col-lg-6 col-xs-12">
 
   <?= $this->google_recaptcha->getWidget() ?>
</div> 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB