Giter Site home page Giter Site logo

civilrightscaptcha-php-library's Introduction

CivilRightsCAPTCHA-PHP-Library

PHP library for Civil Rights Defenders CAPTCHA. Using a library is the simplest way to add the Civil Rights CAPTCHA to your site.

There is a Wiki at http://captcha.civilrightsdefenders.org.

The package includes the library and an example page to demonstrate how to use it. The Civil Rights CAPTCHA depends on the javascript library jQuery.

Step 1: Displaying the CAPTCHA

To display the captcha in your html form, simply echo the show() function at the place in the <form> where you want the captcha to display.

require_once('CRCphplib.php');
$crccaptcha = new civilrightscaptcha();
//To set language use (Sets to Swedish, default is english): 
//$crccaptcha->setLanguage('sv'); 
echo $crccaptcha->show();

A form with the CAPTCHA could look something like this.

<html>
  <head>
  <script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script>
  </head>
  <body>
    <!-- your HTML content -->
 
    <form method="post" action="verify.php">
      <!-- your form inputs -->
      <?php
          require_once('CRCphplib.php');
          $crccaptcha = new civilrightscaptcha();
          echo $crccaptcha->show();
      ?>
      <input type="submit" />
    </form>
 
    <!-- more of your HTML content -->
  </body>
</html>

Notice that the require_once() expects the library file to be in the same catalog as your script. If it is not, you must link approperiately. The jQuery library must be included for the captcha to function.

Step 2: Verifying the entered answer

After the form has been submitted to your form-proccessing-php-file, you must verify that the user entered the correct answer.

require_once('CRCphplib.php');
$crccaptcha = new civilrightscaptcha();
if($crccaptcha->check($_POST['crc_captcha'], $_POST['crc_sessid'])) {
    //Your code if the user entered the correct answer!
}
else {
    //Your code if the user entered the wrong answer!
}

When the user submits the form, two fields (crc_captcha & crc_sessid) are also submitted from the captcha. Both these have to be used as parameters to the check function. The check function returns a boolean TRUE if the answer is correct and FALSE if it is not.

see http://captcha.civilrightsdefenders.org for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.