Welcome Guest, Not a member yet? Register   Sign In
reCAPTCHA library for CodeIgniter Framework
#1

(This post was last modified: 12-09-2014, 02:10 AM by appleboy.)

Github page: https://github.com/appleboy/CodeIgniter-reCAPTCHA

CodeIgniter-reCAPTCHA

The FREE anti-abuse service. Easy to add, advanced security, accessible to wide range of users and platforms.

What is reCAPTCHA?

reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced risk analysis engine to tell humans and bots apart. With the new API, a significant number of your valid human users will pass the reCAPTCHA challenge without having to solve a CAPTCHA (See blog for more details). reCAPTCHA comes in the form of a widget that you can easily add to your blog, forum, registration form, etc.

Sign up for an API key pair To use reCAPTCHA, you need to sign up for an API key pair for your site. The key pair consists of a site key and secret. The site key is used to display the widget on your site. The secret authorizes communication between your application backend and the reCAPTCHA server to verify the user's response. The secret needs to be kept safe for security purposes.

Installation

You can install via http://getsparks.org/packages/recaptcha-library/show

Code:
$ php tools/spark install -v1.0.2 recaptcha-library

or manual install

PHP Code:
cp config/recaptcha.php your_application/config/
cp libraries/recaptcha.php your_application/libraries

Usage

Set your site key and secret on config/recaptcha.php file

PHP Code:
$config['recaptcha_site_key'] = '';
$config['recaptcha_secret_key'] = ''

Render the reCAPTCHA widget

PHP Code:
$this->load->library('recaptcha');
echo 
$this->recaptcha->getWidget(); 

output:

Code:
<div class="g-recaptcha" data-sitekey="xxxx" data-theme="light" data-type="image" data-callback="" ></div>

change default theme by pass array parameter

PHP Code:
echo $this->recaptcha->getWidget(array('data-theme' => 'dark')); 

change default type by pass array parameter

PHP Code:
echo $this->recaptcha->getWidget(array('data-theme' => 'dark''data-type' => 'audio')); 

Render Script Tag

PHP Code:
$this->load->library('recaptcha');
echo 
$this->recaptcha->getScriptTag(); 

output:

Code:
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=onload&hl=en" async defer></script>


change render value by pass array parameter

PHP Code:
echo $this->recaptc[php
ha->getScriptTag(array('render' => 'explicit'));[/php]

change default language by pass array parameter

PHP Code:
echo $this->recaptcha->getScriptTag(array('render' => 'explicit''hl' => 'zh-TW')); 

Verify Response

Calls the reCAPTCHA siteverify API to verify whether the user passes g-recaptcha-response POST parameter.

PHP Code:
$recaptcha $this->input->post('g-recaptcha-response');
$response $this->recaptcha->verifyResponse($recaptcha); 

check success or fail

PHP Code:
if (isset($response['success']) and $response['success'] === true) {
   echo "You got it!";


Author

Bo-Yi Wu @appleboy
Reply
#2

Great job! Thank you .. also for responsive.

Reply




Theme © iAndrew 2016 - Forum software by © MyBB