Source for file example-02.php
Documentation is available at example-02.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* This file is part of the PEAR Services_ReCaptcha package.
* LICENSE: This source file is subject to the MIT license that is available
* through the world-wide-web at the following URI:
* http://opensource.org/licenses/mit-license.php
* @package Services_ReCaptcha
* @author David Jean Louis <izi@php.net>
* @copyright 2008-2009 David Jean Louis
* @license http://opensource.org/licenses/mit-license.php MIT License
* @link http://pear.php.net/package/Services_ReCaptcha
* @link http://recaptcha.net/apidocs/captcha/client.html
* @since File available since release 0.1.0
* Include the Services_ReCaptcha class
require_once 'Services/ReCaptcha.php';
// you must get your API keys here:
// http://recaptcha.net/api/getkey
$publicKey = 'your_public_key';
$privateKey = 'your_private_key';
// we instanciate our Services_ReCaptcha instance with the public key and the
// we are going to customize our Services_ReCaptcha instance
$recaptcha->setOption ('secure', true ); // we force the secure url
$recaptcha->setOption ('theme', 'white'); // use the white theme
$recaptcha->setOption ('lang', 'fr'); // set language to french
// alternatively we could have done:
// $recaptcha = new Services_ReCaptcha($publicKey, $privateKey, array(
// $recaptcha->setOptions(array('theme' => 'white', 'lang' => 'fr'));
// we use a proxy, so we need to configure it
$recaptcha->getRequest ()->setConfig (
array ('proxy_host' => 'localhost', 'proxy_port' => 8118 )
// if the form was submitted
if (isset ($_POST['submit'])) {
if ($recaptcha->validate ()) {
// the catpcha challenge response is ok, we display a message and exit
echo "Challenge response ok !";
// if the captcha validation failed, instead of letting the captcha
// display the error, we want to echo the error and exit
echo $recaptcha->getError ();
// we display the html form
<title>recaptcha test</title>
<form method="post" action="">
<?php echo $recaptcha; ?>
<input type="submit" name="submit" value="Ok"/>
Documentation generated on Mon, 11 Mar 2019 15:43:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|