SEP
2011
20
0 Comments
369 Hits
reCAPTCHA Library for Panada Framework
Posted under: PHP, Panada Framework
Tags: PHP, Panada

reCAPTCHA is a free CAPTCHA service that protects your site against spam, malicious registrations and other forms of attacks where computers try to disguise themselves as a human;

A CAPTCHA is a Completely Automated Public Turing test to tell Computers and Human Apart. reCAPTCHA comes in the form of a widget that you can easily add to your blog, forum, registration form, etc. Therefore, reCAPTCHA has been become the most powerful captcha to prevent against SPAM or automatic form filling script attacks.

To learn how reCAPTCHA works, read it here. There are a PHP plugin for reCAPTCHA which you can download it here and if you would like to read it's documentation, you may read it here.

If you had already running a web application (most likely a website or blog) based on Panada Framework. I had the PHP plugin conversion for Panada Framework library for you to use. You may download the reCAPTCHA library here:

  • Initial release
    reCAPTCHA Panada Framework library v1.0 (9.79 kB)  - download 
    Notes: This library conversion was built based on reCAPTCHA PHP plugin v1.11

Installation

Follow these steps to install and use the library on your Panada application:

  1. Put the downloaded library file on your apps/library/ folder, so it has the following path:
    /apps/library/recaptcha.php where / is your Panada application root directory.
  2. Create your own reCAPTCHA API key here to get your reCAPTCHA public key and private key.
  3. So now you already have your public key and private key.
    Put your public key and private key on your panada application configuration file: /apps/config.php
    Add the following lines to your configuration file:

    /* reCAPTCHA key configuration */
    $CONFIG['recaptcha_publickey'] = "your_public_key";
    $CONFIG['recaptcha_privatekey'] = "your_private_key";

    replace your_public_key with your already created reCAPTCHA public key and replace your_private_key with your reCAPTCHA private key
To show the reCAPTCHA on your view files:

Put the following PHP code on your desired view files:

<?php

    $recaptcha = new library_recaptcha();
    echo $recaptcha->recaptcha_get_html($this->config->recaptcha_publickey); 

?>
 
Please note that it must be placed betweeen the <form> and </form> tags where you need to put the reCAPTCHA on.
 
Handling the reCAPTCHA input
 
To handle the reCAPTCHA, put the following code on your controller files where you handle the form input on server side:
// ... your previous php code ...

$recaptcha = new library_recaptcha;
$resp = $recaptcha->recaptcha_check_answer ($this->config->recaptcha_privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {

    // What happens when the CAPTCHA was entered incorrectly
    die( "The reCAPTCHA wasn't entered correctly. Go back and try it again." . 
    "(reCAPTCHA said: " . $resp->error . ")" );

} 

// ... your next php code ... 
That is it! Quite simple isn't it? Tell me if you had any problem while using the library on your panada application. I would be glad if I can help. And also tell what you think about this library if you find library is useful on your panada application.
Permalink
This post was last updated on: Tuesday, 20 Sep 2011 11:48 and has been read 369 times. Get the permalink of this post or scan the QR Code.


Posted under PHP, Panada Framework categories.
Tagged: PHP, Panada

Write Your Comments

Comments are parsed with Markdown.
 
Notes
* Your email is required to submit this form, and it will not be published or shared without your consent. We use your email address to show your avatar picture profile from Gravatar. Don't have one? Then sign up to gravatar and create your own here.
We also filters your comment against SPAM because we hate SPAM as much as you do. If your comment is recognized as SPAM then it will be moderated, otherwise it will shows up immediately.
Form Key: #6eccb7b1efb6896c051dc9e306a05d22
Loading...