Advertisement
VladimirsBudkins

CI gregwar/captcha lib

Jan 17th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. use Gregwar\Captcha\CaptchaBuilder as GregwarCaptchaBuilder;
  4.  
  5. class CaptchaBuilder {
  6.  
  7.     protected $captchaSessionKey = 'captcha';
  8.     protected $CI;
  9.     protected $captchaBuilder;
  10.  
  11.     public function __construct() {
  12.         $this->CI = &get_instance();
  13.     }
  14.  
  15.     public function init($width = 150, $height = 40, $usePrevCaptcha = false) {
  16.         $captcha = $usePrevCaptcha ? $this->getCaptchaFromSession() : null;
  17.         $this->captchaBuilder = new GregwarCaptchaBuilder($captcha);
  18.         $this->captchaBuilder->build($width, $height);
  19.         $this->CI->session->set_userdata($this->captchaSessionKey, $this->captchaBuilder->getPhrase());
  20.     }
  21.  
  22.     public function getInline() {
  23.         return $this->captchaBuilder->inline();
  24.     }
  25.  
  26.     public function reset() {
  27.         $this->CI->session->unset_userdata($this->captchaSessionKey);
  28.     }
  29.  
  30.     public function setCaptchaSessionKey($key) {
  31.         $this->captchaSessionKey = $key;
  32.         return $this;
  33.     }
  34.  
  35.     public function getCaptchaSessionKey() {
  36.         return $this->captchaSessionKey;
  37.     }
  38.  
  39.     public function check($checkString) {
  40.         return ($checkString == $this->getCaptchaFromSession());
  41.     }
  42.  
  43.     public function getCaptchaFromSession() {
  44.         return isset($this->CI->session->{$this->captchaSessionKey}) ? $this->CI->session->{$this->captchaSessionKey} : null;
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement