Esempio n. 1
0
function validate_captcha()
{
    $captcha = new Captcha\Captcha();
    $captcha->setPublicKey(CONFIG_RECAPTCHA_PUBLIC_KEY);
    $captcha->setPrivateKey(CONFIG_RECAPTCHA_PRIVATE_KEY);
    $response = $captcha->check();
    if (!$response->isValid()) {
        message_error("The reCAPTCHA wasn't entered correctly. Go back and try it again.");
    }
}
Esempio n. 2
0
 /**
  * Fetches the HTML for the captcha.
  *
  * @param array $configuration Configuration data.
  *
  * @static
  * @uses   Core\Session()
  *
  * @return \Captcha\Captcha
  */
 public static function get(array $configuration)
 {
     $captcha = Core\Session()->get('captcha');
     if (!$captcha && Core\Session()->get('authentication_error')) {
         $captcha = new \Captcha\Captcha();
         $captcha->setPublicKey($configuration['public_key']);
         $captcha->setPrivateKey($configuration['private_key']);
         Core\Session()->set('captcha', $captcha);
     }
     return $captcha;
 }
Esempio n. 3
0
 public static function createCaptcha($environment)
 {
     $captcha = new \Captcha\Captcha();
     if (strtolower($environment) == 'production') {
         $captcha->setPublicKey('6LcwQPwSAAAAAEaSdomAVBdEa_ZcPFIENzzAaukT');
         $captcha->setPrivateKey('6LcwQPwSAAAAAEITEtwbGBet_tltApNYbh0oDag9');
     }
     if (strtolower($environment) == 'dev.peter') {
         $captcha->setPublicKey('6LdrO_wSAAAAAKm8_PxSJGreOdLVBAoGP2Gi3zgn');
         $captcha->setPrivateKey('6LdrO_wSAAAAAMH6Ds8YRPAkcKozZX80iGXUsr50');
     }
     return $captcha;
 }
require_once '../../../../config.php';
require_once '../../../../vendor/autoload.php';
require_once '../utils/response.php';
require_once '../utils/session.php';
require_once 'form.php';
Response::allow_method('POST');
session_start();
if (!isset($_POST['token']) || !Session::verify_token('token_form_contact', $_POST['token'])) {
    Response::json(401, 'La sesión es inválida o este formulario ya fue enviado.');
}
unset($_POST['token']);
if (!isset($_POST['recaptcha']) || !isset($_POST['recaptcha']['challenge']) || !isset($_POST['recaptcha']['response'])) {
    Response::json(400, 'Captcha requerido!');
}
// Validate captcha
$captcha = new Captcha\Captcha();
$captcha->setPublicKey(Config::$RECAPTCHA_PUBLIC);
$captcha->setPrivateKey(Config::$RECAPTCHA_SECRET);
$response = $captcha->check($_POST['recaptcha']['challenge'], $_POST['recaptcha']['response']);
if (!$response->isValid()) {
    Response::json(401, 'Captcha inválido!');
}
unset($_POST['recaptcha']);
// Form creation
$MAX_LENGTH_NAME = 30;
$MAX_LENGTH_SUBJECT = 70;
$MAX_LENGTH_MESSAGE = 250;
$REASONS = array('enquiry' => 'Consultas', 'complaint' => 'Reclamos', 'difussion' => 'Bandas/Difusión', 'other' => 'Otros');
$form = new Form(array('full_name' => array('label' => 'Nombre/s', 'type' => 'string', 'required' => true, 'maxlength' => $MAX_LENGTH_NAME), 'email' => array('label' => 'Correo electrónico', 'type' => 'email', 'required' => true), 'reason' => array('label' => 'Motivo', 'type' => 'string', 'required' => true, 'select' => $REASONS), 'subject' => array('label' => 'Asunto', 'type' => 'string', 'required' => true, 'maxlength' => $MAX_LENGTH_SUBJECT), 'message' => array('label' => 'Mensaje', 'type' => 'string', 'required' => true, 'maxlength' => $MAX_LENGTH_MESSAGE)));
$errors = $form->validate_whitelist();
if (!empty($errors)) {
Esempio n. 5
0
function display_captcha()
{
    echo '
        <script type="text/javascript">
         var RecaptchaOptions = {
                theme : "clean"
         };
         </script>
         ';
    $captcha = new Captcha\Captcha();
    $captcha->setPublicKey(CONFIG_RECAPTCHA_PUBLIC_KEY);
    $captcha->setPrivateKey(CONFIG_RECAPTCHA_PRIVATE_KEY);
    echo $captcha->html();
}
Esempio n. 6
0
<?php

session_start();
/**
 * @author Dominik Ryńko <http://www.rynko.pl/>
 * @version 1.0.0
 * @license http://creativecommons.org/licenses/by-sa/3.0/pl/
 */
// Set default charset and document type
header('Content-Type: text/html; charset=utf-8');
// Check PHP version
if (version_compare(PHP_VERSION, '4.3.0') <= 0) {
    exit('Script requires 4.3.0 or higher version of PHP. My version is: ' . PHP_VERSION);
}
$className = 'Captcha.class.php';
if (file_exists($className) && filesize($className) !== 0) {
    require $className;
    try {
        $config = array('font' => 'arial.ttf', 'dir' => 'font');
        $captcha = new Captcha\Captcha($config);
        $captcha->CaptchaSecurityImages(120, 40, 4);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
} else {
    return 'File: ' . $className . ' does not exist. Cannot load module.';
}
Esempio n. 7
0
<?php

/**
 * You must run `composer install` in order to generate autoloader for this example
 */
require __DIR__ . '/../vendor/autoload.php';
// New captcha instance
$captcha = new Captcha\Captcha();
$captcha->setPublicKey('publickey');
$captcha->setPrivateKey('privatekey');
// set a remote IP if the remote IP can not be found via $_SERVER['REMOTE_ADDR']
if (!isset($_SERVER['REMOTE_ADDR'])) {
    $captcha->setRemoteIp('192.168.1.1');
}
// Output captcha to end user
echo $captcha->html();
// Perform validation (put this inside if ($_POST) {} condition for example)
$response = $captcha->check();
if (!$response->isValid()) {
    echo $response->getError();
}