/** * Returns a singleton instance of the CaptchaBuilder * * @return \Gregwar\Captcha\CaptchaBuilder */ protected function getCatpchaBuilder($reset = false) { static $captchaBuilder = null; if ($captchaBuilder === null || $reset === true) { $captchaBuilder = \Gregwar\Captcha\CaptchaBuilder::create(); } return $captchaBuilder; }
/** * @param string $phrase * @return bool */ public function verifyCaptcha($phrase) { if ($phrase) { $ip = Request::get()->getRequest()->ip; $key = md5($phrase . $ip); $v = getCache()->get($key); $b = CaptchaBuilder::create($v); if ($b->testPhrase($phrase)) { return true; } } return false; }
<?php include __DIR__ . '/../CaptchaBuilderInterface.php'; include __DIR__ . '/../PhraseBuilderInterface.php'; include __DIR__ . '/../CaptchaBuilder.php'; include __DIR__ . '/../PhraseBuilder.php'; use Gregwar\Captcha\CaptchaBuilder; header('Content-type: image/jpeg'); CaptchaBuilder::create()->build()->output();
<?php include __DIR__ . '/../CaptchaBuilderInterface.php'; include __DIR__ . '/../PhraseBuilderInterface.php'; include __DIR__ . '/../CaptchaBuilder.php'; include __DIR__ . '/../PhraseBuilder.php'; use Gregwar\Captcha\CaptchaBuilder; echo count(CaptchaBuilder::create()->build()->getFingerprint()); echo "\n";
/** * Create render * @param string $code * @return ICaptchaRender */ public function create($code) { return CaptchaBuilder::create($code)->build(); }
public static function captcha($name) { $builder = CaptchaBuilder::create()->build(); Controller::$instance->session->set('captcha_' . $name, ['phrase' => $builder->getPhrase(), 'try' => 0]); return $builder->inline(); }