Form protection from spam without captcha in Bitrix and not only
Rus
Eng
Защита формы от спама без captcha в Битрикс и не только

All English-language materials have been translated fully automatically using the Google service

Sooner or later, on all sites, it becomes necessary to protect feedback or registration / authorization forms from spambots. Captcha cannot cope with protection, and it is not user-friendly either. But there are ways to protect yourself through hidden fields in forms. This method is quite effective against most bots, since it requires manual analysis of the form and the waste of the spammer's personal time, which is spent on very few and in rare cases.

First of all, we will copy the entire component into our namespace (to make changes to the base class), rename the .default template with the name we need, and make all changes in it.

Ie copy, for example, the folder /bitrix/components/bitrix/system.auth.registration to /local/components/tichiy/system.auth.registration and work in it

Then add a regular input with a random meaningful name to the template form code

 <div class = 'newTR'> <input type = "text" name = "EMAIL" maxlength = "50" placeholder = "Enter your email" value = "" /> </div>

In css we write styles that hide this field from well-intentioned users

.newTR {display:none } 

If not, then add the file result_modifier.php and add

to the very end
  $ arResult ['EMAIL'] = isset ($ _ POST ['EMAIL'])? htmlspecialcharsbx ($ _ POST ['EMAIL']): '';  

In the file /local/php_interface/handlers/user_register.php add a bot detector handler. It will fire on the OnBeforeUserRegister event of the main module. If our fake field is filled, then we throw out the bitrix exception and add an error message.

  namespace Tichiy;

class UserRegister {
    / **
     * Called before attempting to register a new user with the CUser :: Register method.
     * Check for a bot.
     * @param & $ arFields Array of new user registration fields
     * @return bool
     * /
    public static function OnBeforeUserRegister (& $ arFields) {
        global $ APPLICATION;
 
        if (isset ($ _ REQUEST ['EMAIL'])
            && strlen (trim ($ _ REQUEST ['EMAIL']))> 0) {
 
           // for completeness, write all the fields filled in by the bot to the system log
            \ CEventLog :: Add (array (
                "SEVERITY" => "SECURITY",
                "AUDIT_TYPE_ID" => "USER_REGISTER_FAIL",
                "MODULE_ID" => "main",
                "ITEM_ID" => "UNKNOWN",
                "DESCRIPTION" => sprintf ("Attempt to register by bot. Error code [FK1]. \ N% s",
                    var_export ($ _ REQUEST, true)),
            ));
 
            $ APPLICATION-> ThrowException ('Registration failed. Error code [FK1].');
            return false;
        }
        return true;
 
    }
 
}  

In /local/php_interface/init.php , add our handler autoloading and attach the handler:

  / **
 * Treatment for registration without captcha
 * /
\ Bitrix \ Main \ EventManager :: getInstance () -> AddEventHandler ('main', 'OnBeforeUserRegister', array ('Tichiy \ UserRegister', 'OnBeforeUserRegister'));
 
CModule :: AddAutoloadClasses ('', array ('Tichiy \ UserRegister' => '/bitrix/php_interface/handlers/user_register.php',));  

Material adaptation:

Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Are you developing a new service, making improvements to the existing one and want to be better than your competitors? You have come to the right place. I offer you a comprehensive studio-level website development. From me you can order design, layout, programming, development of non-traditional functionality, implementation of communication between CMS, CRM and Data Analitics, as well as everything else related to sites, except for promotion.

Contact, I will always advise on all questions and help you find the most effective solution for your business. I am engaged in the creation of sites in Novosibirsk and in other regions of Russia, I also work with the CIS countries. You will be satisfied with our cooperation

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site

Contact with me
Send message
By submitting the form, you automatically confirm that you have read and accept Privacy policy of site
Sending successful!
Thank you for contacting :) I will contact you as soon as possible
Sending failed
An error occurred while sending the request. Please wait and try again after a while or call my phone number