<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                主要解決方法: 1)繼承Yii2的yii\captcha\CaptchaAction,重寫run方法進行驗證碼的生成、顯示等操作。 2)改變getVerifyCode的參數false改為true,讓每次刷新和請求都更新驗證碼 3)讓驗證碼更美觀,用新的字體,加上線條,背景等 有其他特殊需求可以在這些代碼中自己添加即可。 控制器代碼SiteController.php: public function actions() { return [ 'captcha' => [ 'class' => 'common\components\MyCaptcha', //'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, 'maxLength' => 4, //生成的驗證碼最大長度 'minLength' => 4, //生成的驗證碼最短長度 'width'=>130, 'height'=>50, ], ]; } 驗證碼common/components/MyCaptcha.php: <?php namespace common\components; use Yii; use yii\captcha\CaptchaAction; use yii\helpers\Url; use yii\web\Response; class MyCaptcha extends CaptchaAction { public function init() { parent::init(); $this->fontFile = dirname(Yii::$app->basePath) . '/source/font/elephant.ttf'; } /** * Runs the action. */ public function run() { if (Yii::$app->request->getQueryParam(self::REFRESH_GET_VAR) !== null) { // AJAX request for regenerating code $code = $this->getVerifyCode(true); Yii::$app->response->format = Response::FORMAT_JSON; return [ 'hash1' => $this->generateValidationHash($code), 'hash2' => $this->generateValidationHash(strtolower($code)), // we add a random 'v' parameter so that FireFox can refresh the image // when src attribute of image tag is changed 'url' => Url::to([$this->id, 'v' => uniqid()]), ]; } else { $this->setHttpHeaders(); Yii::$app->response->format = Response::FORMAT_RAW; return $this->renderImage($this->getVerifyCode(true)); } } /** * Renders the CAPTCHA image based on the code using GD library. * @param string $code the verification code * @return string image contents in PNG format. */ protected function renderImageByGD($code) { $image = imagecreatetruecolor($this->width, $this->height); $backColor = imagecolorallocate($image, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255)); imagefilledrectangle($image, 0, 0, $this->width - 1, $this->height - 1, $backColor); imagecolordeallocate($image, $backColor); if ($this->transparent) { imagecolortransparent($image, $backColor); } $foreColor = imagecolorallocate($image,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156)); //雪花線條 for ($i=0;$i<6;$i++) { $color = imagecolorallocate($image,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156)); imageline($image,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color); } for ($i=0;$i<100;$i++) { $color = imagecolorallocate($image,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)); imagestring($image,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color); } $length = strlen($code); $box = imagettfbbox(30, 0, $this->fontFile, $code); $w = $box[4] - $box[0] + $this->offset * ($length - 1); $h = $box[1] - $box[5]; $scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h); $x = 10; $y = round($this->height * 27 / 40); for ($i = 0; $i < $length; ++$i) { $fontSize = (int) (rand(26, 32) * $scale * 0.8); $angle = rand(-10, 10); $letter = $code[$i]; $box = imagettftext($image, $fontSize, $angle, $x, $y, $foreColor, $this->fontFile, $letter); $x = $box[2] + $this->offset; } imagecolordeallocate($image, $foreColor); ob_start(); imagepng($image); imagedestroy($image); return ob_get_clean(); } } 視圖中的代碼: <ul> <li><i class="icon-user"></i><input type="text" id="user" placeholder="請輸入賬號" maxlength="20" autocomplete="false"><span></span></li> <li><i class="icon-pwd"></i><input type="password" id="pwd" placeholder="請輸入密碼" maxlength="20" autocomplete="false"><span></span></li> <li><i class="icon-ver"></i><input type="text" id="ver" placeholder="請輸入驗證碼" maxlength="4" autocomplete="false"><span></span> <?php echo Captcha::widget(['name'=>'captchaimg','captchaAction'=>'site/captcha','imageOptions'=>['class'=>'captchaimg', 'title'=>'換一個', 'alt'=>'換一個'],'template'=>'{image}']);?></li> <li><button id="login">登錄</button></li> </ul> <script type="text/javascript"> $(".captchaimg").click(function(){ var date = new Date(); $(this).attr('src',['site/captcha','data=',(new Date())].join('?')); }) <script>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看