A
A
anriko2021-02-01 20:02:52
1C-Bitrix
anriko, 2021-02-01 20:02:52

How to attach google recaptcha init.php to system.auth.registration itrix registration form?

use \Bitrix\Main\Mail\Event;

AddEventHandler('form', 'onAfterResultAdd', 'my_onAfterResultAddUpdate');
function my_onAfterResultAddUpdate($WEB_FORM_ID, $RESULT_ID)
{
    /*capcha */
    if (isset($_POST['recaptcha_response'])) {

        $recaptcha_key = 'секретный ключ';


        $recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
        $recaptcha_params = [
            'secret' => $recaptcha_key,
            'response' => $_POST['recaptcha_response'],
            'remoteip' => $_SERVER['REMOTE_ADDR'],
        ];

        $ch = curl_init($recaptcha_url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $recaptcha_params);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        $response = curl_exec($ch);
        if (!empty($response)) {
            $decoded_response = json_decode($response);
        }

        $recaptcha_success = false;
        //dbg2f($decoded_response, 'responce');

        if ($decoded_response && $decoded_response->score > 0) {
            $recaptcha_success = $decoded_response->score;
            // ???????????? ?????? ?????, ??????? ???????? ??????
        } else {
            // ??????????? ????????, ???? ???????????? ???????? ?????
        }

    }

    /*capcha */
/*&& $recaptcha_success > 0.5*/
    if ($WEB_FORM_ID ==   'КАК ТУТ ПРОВЕРИТЬ НА ФОРМУ РЕГИСТРАЦИИ' && $recaptcha_success > 0.5){
    }

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question