Пример #1
0
<?php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
require_once '../CaptchaGenerator.php';
// Einfache Anwendung.
try {
    $captcha = new CaptchaGenerator(dirname($_SERVER["SCRIPT_FILENAME"]) . '/arial.ttf', dirname($_SERVER["SCRIPT_FILENAME"]) . '/pwdimage.png', 4);
    // Intervene here the phrase
    // and save it into the database or at the session.
    $_SESSION['security-phrase'] = $captcha->getPhrase();
    $captcha->render();
} catch (InvalidArgumentException $e) {
    print $e->getMessage();
}
Пример #2
0
 public function __construct($config = [])
 {
     if (self::$defaultConfig === null) {
         self::$defaultConfig = ['code' => '', 'min_length' => 5, 'max_length' => 5, 'backgrounds' => [CAPTCHA_BG_PATH . '45-degree-fabric.png', CAPTCHA_BG_PATH . 'cloth-alike.png', CAPTCHA_BG_PATH . 'grey-sandbag.png', CAPTCHA_BG_PATH . 'kinda-jean.png', CAPTCHA_BG_PATH . 'polyester-lite.png', CAPTCHA_BG_PATH . 'stitched-wool.png', CAPTCHA_BG_PATH . 'white-carbon.png', CAPTCHA_BG_PATH . 'white-wave.png'], 'fonts' => [CAPTCHA_FONTS_PATH . 'times_new_yorker.ttf'], 'characters' => 'ABCDEFGHJKLMNPRSTUVWXYZabcdefghjkmnprstuvwxyz23456789', 'min_font_size' => 28, 'max_font_size' => 28, 'color' => '#666', 'angle_min' => 0, 'angle_max' => 10, 'shadow' => true, 'shadow_color' => '#fff', 'shadow_offset_x' => -1, 'shadow_offset_y' => 1];
     }
     $this->captchaConfig = self::$defaultConfig;
     foreach ($config as $key => $value) {
         $this->captchaConfig[$key] = $value;
     }
     $this->_prepareConfig();
     $this->redisConnect = new \Predis\Client(['scheme' => 'tcp', 'host' => $this->captchaConfig['redis']['server'], 'port' => $this->captchaConfig['redis']['port']]);
 }
 public function testGetPhraseHaseExpectedLength()
 {
     $this->assertEquals($this->_phraselength, mb_strlen($this->_captcha->getPhrase()));
 }