瀏覽代碼

Новая капча

vadeg_ne@mail.ru 1 年之前
父節點
當前提交
be4c9c3695
共有 2 個文件被更改,包括 4 次插入4 次删除
  1. 2 1
      controllers/NewsController.php
  2. 2 3
      views/news/view/comments/list.php

+ 2 - 1
controllers/NewsController.php

@@ -192,8 +192,9 @@ class NewsController extends Controller
 			$this->redirect($model->getUrl(true).$queryString, 301);
 			return '';
 		}
+
         if(\Yii::$app->request->isPost){
-            $capcha_result = \Yii::$app->session->getFlash('capcha_a')+\Yii::$app->session->getFlash('capcha_b');
+            $capcha_result = ceil(base64_decode(\Yii::$app->request->post('capcha_salt'))*3.14);
             if(
                 \Yii::$app->request->post('capcha')=="" ||
                 \Yii::$app->request->post('capcha')!= $capcha_result

+ 2 - 3
views/news/view/comments/list.php

@@ -98,10 +98,9 @@ $query = $model->getCommentsAll()->orderBy(['created_at'=>SORT_ASC])->andWhere([
                 <?php
                     $a = rand(1,9);
                     $b = rand(1,9);
-                    $answer  = $a + $b;
-                    Yii::$app->session->setFlash('capcha_a',$a);
-                    Yii::$app->session->setFlash('capcha_b',$b);
+
                 ?>
+                <input type="hidden" name="capcha_salt" value="<?=base64_encode(($a+$b)/3.14);?>">
                 <label for="capcha">Решите пример: <i style="opacity: 0;">1</i><?=$a?><i style="opacity: 0;">0</i>+<i style="opacity: 0;">2</i><?=$b?><i style="opacity: 0;">0</i>=</label>
                 <input type="text" name="capcha" style="outline: none;border: 1px solid #212529;width: 25px;" aria-label="capcha">
             </div>