123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace common\helpers;
- use yii\caching\Cache;
- use yii\captcha\CaptchaAction;
- class CodeImgGenerate extends CaptchaAction
- {
- private $verifycode;
- public function __construct($id, $controller)
- {
- parent::__construct($id, $controller);
- $this->init();
-
-
- $this->maxLength = 4;
- $this->minLength = 4;
- $this->backColor = 0x000000;
- $this->foreColor = 0x00ff00;
- $this->width = 100;
- $this->height = 58;
- $this->backColor = Util::captcha_color(1);
- $this->foreColor = Util::captcha_color(2);
- $this->padding = 0;
- $this->offset = 4;
- }
-
- public function inline()
- {
- return $this->renderImage($this->getPhrase());
- }
-
- public function getPhrase()
- {
- if(!$this->verifycode){
- }
- $this->verifycode = (string)rand(1234, 9999);
- \Yii::$app->cache->set($this->getSessionKey() . '/' . $this->verifycode, $this->verifycode);
- return $this->verifycode;
- }
- public function validate($input, $caseSensitive = false)
- {
- $code = \Yii::$app->cache->get($this->getSessionKey() . '/' . $input);
- $valid = strcasecmp($input, $code) === 0;
- return $valid;
- }
- }
- ?>
|