Bladeren bron

Новая капча

vadeg_ne@mail.ru 1 jaar geleden
bovenliggende
commit
be4c9c3695
2 gewijzigde bestanden met toevoegingen van 4 en 4 verwijderingen
  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>