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){
}
} // регистрируем обработчик события "OnBeforeUserRegister"
RegisterModuleDependences("main", "OnBeforeUserRegister", "my_module_id", "MyClass", "OnBeforeUserRegisterHandler");
<?
// файл /bitrix/modules/my_module_id/include.php
class MyClass
{
// создаем обработчик события "OnBeforeUserRegister"
function OnBeforeUserRegisterHandler(&$arFields)
{
/*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 */
if ($recaptcha_success < 0.5)
{
// ОТМЕНА РЕГИСТРАЦИИ ,КАК НАПИСАТЬ ?
$GLOBALS['APPLICATION']->ThrowException(' рекапча не заполнена это бот ');
return false;
}
return true;
}
}
?> AddEventHandler('main', 'OnBeforeUserRegister', 'OnBeforeUserRegisterHandler');
function OnBeforeUserRegisterHandler(&$arFields){
global $APPLICATION;
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);
$response = json_decode($response);
if ( $response->success === false ){
$APPLICATION->ThrowException('Ошибка прохождения ReCaptcha.');
return false;
}
if ( $response->score <= 0.5 ){
$APPLICATION->ThrowException('ReCaptcha не пройдена.');
return false;
}
} else {
$APPLICATION->ThrowException('ReCaptcha отсутствует.');
return false;
}
}а куда попадет это сообщение
AddEventHandler("main", "OnBeforeUserRegister", "OnBeforeUserRegisterHandler");
function OnBeforeUserRegisterHandler($args)
{
/*capcha */
if (isset($args['recaptcha_response'])) {
$recaptcha_key = ' секретный код';
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_params = [
'secret' => $recaptcha_key,
'response' => $args['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 {
// прописываем действие, если пользователь оказался ботом
}
}
if ($recaptcha_success >= 0.5){
global $APPLICATION;
$APPLICATION->ThrowException('ReCaptcha не пройдена.');
return false;
}
}Array
(
[LOGIN] => testtest
[NAME] => test2
[LAST_NAME] => test
[PASSWORD] => testtest
[CHECKWORD] => fc543410d07e8dd55cf57494020c074c
[~CHECKWORD_TIME] => now()
[CONFIRM_PASSWORD] => testtest
[EMAIL] => test@gmail.com
[PHONE_NUMBER] =>
[ACTIVE] => N
[CONFIRM_CODE] => 3J1m0ilB
[SITE_ID] => s1
[LANGUAGE_ID] => ru
[USER_IP] => 178.34.158.34
[USER_HOST] => 178.34.158.34
[GROUP_ID] => Array
(
[0] => 5
)
) AddEventHandler("main", "OnBeforeUserRegister", "OnBeforeUserRegisterHandler");
function OnBeforeUserRegisterHandler($args)
{
/*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 {
// ??????????? ????????, ???? ???????????? ???????? ?????
}
}
if ($recaptcha_success < 0.5){
global $APPLICATION;
$APPLICATION->ThrowException('ReCaptcha ?? ???????? ??? ???');
return false;
}
return true;
}