Captcha (капча или каптча) - замена стандартной на свою настраиваемую

Правила раздела: faq.php?mode=okay
Модератор: Модераторы

Kirill
Kirill

Сообщение #21 Kirill » 18.07.2017, 18:06

Парни, подскажите куда добавить проверку на спам с http в файл indexview.php для версии 1.3.5

Код: Выделить всё

<?php

require_once('View.php');

class IndexView extends View {
   
    public $modules_dir = 'view/';
   
    public function __construct() {
        parent::__construct();
    }
   
    public function fetch() {

        if($this->request->method('post') && $this->request->post('callback')) {
            $callback = new stdClass();
            $callback->phone        = $this->request->post('phone');
            $callback->name         = $this->request->post('name');
            $callback->url          = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $callback->message      = $this->request->post('message');
           
            $this->design->assign('callname',  $callback->name);
            $this->design->assign('callemail', $callback->phone);
            $this->design->assign('callmessage', $callback->message);
            $this->design->assign('call_sent', true);
            $callback_id = $this->callbacks->add_callback($callback);
            // Отправляем email
            $this->callbacks->email_callback_admin($callback_id);
        }
       
        // E-mail подписка
        if ($this->request->post('subscribe')) {
            $email = $this->request->post('subscribe_email');
            $this->db->query("select count(id) as cnt from __subscribe_mailing where email=?", $email);
            $cnt = $this->db->result('cnt');
            if (empty($email)) {
                $this->design->assign('subscribe_error', 'empty_email');
            } elseif ($cnt > 0) {
                $this->design->assign('subscribe_error', 'email_exist');
            } else {
                $this->db->query("insert into __subscribe_mailing set email=?", $email);
                $this->design->assign('subscribe_success', '1');
            }
        }
       
        // Содержимое корзины
        $this->design->assign('cart',      $this->cart->get_cart());
       
        // Избранное
        @$wished = (array)explode(',', $_COOKIE['wished_products']);
        $this->design->assign('wished_products', ($wished[0] > 0) ? $wished : array());
       
        // Сравнение
        //unset($_SESSION['comparison']);
      $this->design->assign('comparison', $this->comparison->get_comparison());
       
        // Категории товаров
        $this->count_visible($this->categories->get_categories_tree());
        $this->design->assign('categories', $this->categories->get_categories_tree());
       
        // Страницы
        $pages = $this->pages->get_pages(array('visible'=>1));
        $this->design->assign('pages', $pages);

        $is_mobile = $this->design->is_mobile();
        $is_tablet = $this->design->is_tablet();
        $this->design->assign('is_mobile',$is_mobile);
        $this->design->assign('is_tablet',$is_tablet);
       
        // Текущий модуль (для отображения центрального блока)
        $module = $this->request->get('module', 'string');
        $module = preg_replace("/[^A-Za-z0-9]+/", "", $module);
       
        // Если не задан - берем из настроек
        if(empty($module)) {
            return false;
        }
       
        // Создаем соответствующий класс
        if (is_file($this->modules_dir."$module.php")) {
            include_once($this->modules_dir."$module.php");
            if (class_exists($module)) {
                $this->main = new $module($this);
            } else {
                return false;
            }
        } else {
            return false;
        }
       
        // Создаем основной блок страницы
        if (!$content = $this->main->fetch()) {
            return false;
        }
       
        // Передаем основной блок в шаблон
        $this->design->assign('content', $content);
       
        // Передаем название модуля в шаблон, это может пригодиться
        $this->design->assign('module', $module);
       
        // Создаем текущую обертку сайта (обычно index.tpl)
        $wrapper = $this->design->get_var('wrapper');
        if(is_null($wrapper)) {
            $wrapper = 'index.tpl';
        }

        if(empty($_SESSION['admin'])) {
            if ($this->settings->site_work == "off") {
                header('HTTP/1.0 503 Service Temporarily Unavailable');
                header('Status: 503 Service Temporarily Unavailable');
                header('Retry-After: 300');//300 seconds
                return $this->design->fetch('tech.tpl');
            }
        }
       
        if(!empty($wrapper)) {
            return $this->body = $this->design->fetch($wrapper);
        } else {
            return $this->body = $content;
        }
    }

    private function count_visible($categories = array()) {
        $all_categories = $this->categories->get_categories();
        foreach ($categories as $category) {
            $category->has_children_visible = 0;
            if ($category->parent_id && $category->visible) {
                $all_categories[$category->parent_id]->has_children_visible = 1;
            }
            if ($category->subcategories) {
                $this->count_visible($category->subcategories);
            }
        }
    }
   
}


Добавлено спустя 14 минут 28 секунд:
ой, те для 1.2.3 версии))

вот это я сделал

1) в файле IndexView.php после строки

Код: Выделить всё

$callback->message      = $this->request->post('message');

добавляем

Код: Выделить всё

$pos = stripos($callback->message, 'http');


а куда добавить вот эту проверку не пойму

2) И в том же файле чуть ниже в валидации данных клиента добавляем новое условие

Код: Выделить всё

} elseif($pos !== false) {
               $this->design->assign('error', 'spam_detected');

Dodger M
Аватара
Dodger M
Возраст: 39
Репутация: 0
Сообщения: 23
Зарегистрирован: 23.10.2016
С нами: 7 лет 5 месяцев
Откуда: Москва

Сообщение #22 Dodger » 13.09.2017, 05:48

Kirill писал(а):Парни, подскажите куда добавить проверку на спам с http в файл indexview.php для версии 1.3.5

Код: Выделить всё

<?php

require_once('View.php');

class IndexView extends View {
   
    public $modules_dir = 'view/';
   
    public function __construct() {
        parent::__construct();
    }
   
    public function fetch() {

        if($this->request->method('post') && $this->request->post('callback')) {
            $callback = new stdClass();
            $callback->phone        = $this->request->post('phone');
            $callback->name         = $this->request->post('name');
            $callback->url          = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $callback->message      = $this->request->post('message');
           
            $this->design->assign('callname',  $callback->name);
            $this->design->assign('callemail', $callback->phone);
            $this->design->assign('callmessage', $callback->message);
            $this->design->assign('call_sent', true);
            $callback_id = $this->callbacks->add_callback($callback);
            // Отправляем email
            $this->callbacks->email_callback_admin($callback_id);
        }
       
        // E-mail подписка
        if ($this->request->post('subscribe')) {
            $email = $this->request->post('subscribe_email');
            $this->db->query("select count(id) as cnt from __subscribe_mailing where email=?", $email);
            $cnt = $this->db->result('cnt');
            if (empty($email)) {
                $this->design->assign('subscribe_error', 'empty_email');
            } elseif ($cnt > 0) {
                $this->design->assign('subscribe_error', 'email_exist');
            } else {
                $this->db->query("insert into __subscribe_mailing set email=?", $email);
                $this->design->assign('subscribe_success', '1');
            }
        }
       
        // Содержимое корзины
        $this->design->assign('cart',      $this->cart->get_cart());
       
        // Избранное
        @$wished = (array)explode(',', $_COOKIE['wished_products']);
        $this->design->assign('wished_products', ($wished[0] > 0) ? $wished : array());
       
        // Сравнение
        //unset($_SESSION['comparison']);
      $this->design->assign('comparison', $this->comparison->get_comparison());
       
        // Категории товаров
        $this->count_visible($this->categories->get_categories_tree());
        $this->design->assign('categories', $this->categories->get_categories_tree());
       
        // Страницы
        $pages = $this->pages->get_pages(array('visible'=>1));
        $this->design->assign('pages', $pages);

        $is_mobile = $this->design->is_mobile();
        $is_tablet = $this->design->is_tablet();
        $this->design->assign('is_mobile',$is_mobile);
        $this->design->assign('is_tablet',$is_tablet);
       
        // Текущий модуль (для отображения центрального блока)
        $module = $this->request->get('module', 'string');
        $module = preg_replace("/[^A-Za-z0-9]+/", "", $module);
       
        // Если не задан - берем из настроек
        if(empty($module)) {
            return false;
        }
       
        // Создаем соответствующий класс
        if (is_file($this->modules_dir."$module.php")) {
            include_once($this->modules_dir."$module.php");
            if (class_exists($module)) {
                $this->main = new $module($this);
            } else {
                return false;
            }
        } else {
            return false;
        }
       
        // Создаем основной блок страницы
        if (!$content = $this->main->fetch()) {
            return false;
        }
       
        // Передаем основной блок в шаблон
        $this->design->assign('content', $content);
       
        // Передаем название модуля в шаблон, это может пригодиться
        $this->design->assign('module', $module);
       
        // Создаем текущую обертку сайта (обычно index.tpl)
        $wrapper = $this->design->get_var('wrapper');
        if(is_null($wrapper)) {
            $wrapper = 'index.tpl';
        }

        if(empty($_SESSION['admin'])) {
            if ($this->settings->site_work == "off") {
                header('HTTP/1.0 503 Service Temporarily Unavailable');
                header('Status: 503 Service Temporarily Unavailable');
                header('Retry-After: 300');//300 seconds
                return $this->design->fetch('tech.tpl');
            }
        }
       
        if(!empty($wrapper)) {
            return $this->body = $this->design->fetch($wrapper);
        } else {
            return $this->body = $content;
        }
    }

    private function count_visible($categories = array()) {
        $all_categories = $this->categories->get_categories();
        foreach ($categories as $category) {
            $category->has_children_visible = 0;
            if ($category->parent_id && $category->visible) {
                $all_categories[$category->parent_id]->has_children_visible = 1;
            }
            if ($category->subcategories) {
                $this->count_visible($category->subcategories);
            }
        }
    }
   
}



ой, те для 1.2.3 версии))

вот это я сделал

1) в файле IndexView.php после строки

Код: Выделить всё

$callback->message      = $this->request->post('message');

добавляем

Код: Выделить всё

$pos = stripos($callback->message, 'http');


а куда добавить вот эту проверку не пойму

2) И в том же файле чуть ниже в валидации данных клиента добавляем новое условие

Код: Выделить всё

} elseif($pos !== false) {
               $this->design->assign('error', 'spam_detected');

Попробуйте сделать, чтобы выглядело так:

Код: Выделить всё

       
        if($this->request->method('post') && $this->request->post('callback')) {
            $callback = new stdClass();
            $callback->phone        = $this->request->post('phone');
            $callback->name         = $this->request->post('name');
            $callback->url          = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
            $callback->message      = $this->request->post('message');
            $pos = stripos($callback->message, 'http');
         
            $this->design->assign('callname',  $callback->name);
            $this->design->assign('callemail', $callback->phone);
            $this->design->assign('callmessage', $callback->message);
            $this->design->assign('call_sent', true);
            $callback_id = $this->callbacks->add_callback($callback);
         
         } elseif($pos !== false) {
               $this->design->assign('error', 'spam_detected');
         
            // Отправляем email
            $this->callbacks->email_callback_admin($callback_id);
        }

yura_kr
yura_kr
Репутация: 0
Сообщения: 1
Зарегистрирован: 30.09.2017
С нами: 6 лет 5 месяцев

Сообщение #23 yura_kr » 30.09.2017, 08:34

Kirill, Dodger, Удалось вам реализовать этот фильтр спама. Что-то у меня ничего не работает. Всё сделал , как в сообщении выше, но нет результата.

Код: Выделить всё

$pos = stripos($callback->message, 'http');

И что такое этот stripos ?

korshunov
korshunov
Репутация: 146
Сообщения: 1854
Зарегистрирован: 03.12.2015
С нами: 8 лет 3 месяца
Skype

Сообщение #24 korshunov » 30.09.2017, 09:30

yura_kr писал(а):И что такое этот stripos ?

Функция PHP:
http://www.php.su/stripos


Название раздела: Полезные решения для OkayCMS
Правила раздела: faq.php?mode=okay

Быстрый ответ


Введите код в точности так, как вы его видите. Регистр символов не имеет значения.
Код подтверждения

   

Вернуться в «Полезные решения для OkayCMS»

Кто сейчас на форуме (по активности за 5 минут)

Сейчас этот раздел просматривают: 15 гостей